XStream and Google App Engine

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

XStream and Google App Engine

Xybrek
Hi I saw a XStream implementation for Google App Engine however I am
still getting a "Cannot construct [class] as it does no have a no-args
constructor:

        @Test
        public void testNoNoArgs() {
                Car car = new Car(1, "Blue");
                XStream xstream = new XStreamGae();
                String s = xstream.toXML(car);
                Car c = (Car) xstream.fromXML(s);
        }


The complete stack trace is here: http://pastebin.com/TGF6N17W

The XStream related dependency in my application are:

                <dependency>
                        <groupId>com.thoughtworks.xstream</groupId>
                        <artifactId>xstream</artifactId>
                        <version>1.4.2</version>
                </dependency>
                <dependency>
                        <groupId>xpp3</groupId>
                        <artifactId>xpp3_min</artifactId>
                        <version>1.1.4c</version>
                </dependency>
                <!-- XStreamGae Dependencies -->
                <dependency>
                        <groupId>net.sf.kxml</groupId>
                        <artifactId>kxml2-min</artifactId>
                        <version>2.3.0</version>
                </dependency>
                <dependency>
                        <groupId>xmlpull</groupId>
                        <artifactId>xmlpull</artifactId>
                        <version>1.1.3.1</version>
                </dependency>

The XStreamGae class can be found here:

http://www.wappworks.com/2011/11/11/using-xstream-with-google-app-engine/

Is there a work-around to make this work-around work?




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: XStream and Google App Engine

Jörg Schaible-3
Hi,

Xybrek wrote:

> Hi I saw a XStream implementation for Google App Engine however I am
> still getting a "Cannot construct [class] as it does no have a no-args
> constructor:
>
> @Test
> public void testNoNoArgs() {
> Car car = new Car(1, "Blue");
> XStream xstream = new XStreamGae();
> String s = xstream.toXML(car);
> Car c = (Car) xstream.fromXML(s);
> }
>
>
> The complete stack trace is here: http://pastebin.com/TGF6N17W
>
> The XStream related dependency in my application are:
>
> <dependency>
> <groupId>com.thoughtworks.xstream</groupId>
> <artifactId>xstream</artifactId>
> <version>1.4.2</version>
> </dependency>
> <dependency>
> <groupId>xpp3</groupId>
> <artifactId>xpp3_min</artifactId>
> <version>1.1.4c</version>
> </dependency>

Xpp3 is superfluous, since ...

> <!-- XStreamGae Dependencies -->
> <dependency>
> <groupId>net.sf.kxml</groupId>
> <artifactId>kxml2-min</artifactId>
> <version>2.3.0</version>
> </dependency>

... XStreamGae uses kXML2 instead.

> <dependency>
> <groupId>xmlpull</groupId>
> <artifactId>xmlpull</artifactId>
> <version>1.1.3.1</version>
> </dependency>
>
> The XStreamGae class can be found here:
>
> http://www.wappworks.com/2011/11/11/using-xstream-with-google-app-engine/
>
> Is there a work-around to make this work-around work?

No. As you can see, XStreamGae is explicitly initialized in pure Java mode,
because the enhanced mode *cannot* work with GAE due to its security policy.
You will have to add a no-arg constructor.

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: XStream and Google App Engine

Xybrek
On 04/04/2013 03:32 PM, Jörg Schaible wrote:

> Hi,
>
> Xybrek wrote:
>
>> Hi I saw a XStream implementation for Google App Engine however I am
>> still getting a "Cannot construct [class] as it does no have a no-args
>> constructor:
>>
>> @Test
>> public void testNoNoArgs() {
>> Car car = new Car(1, "Blue");
>> XStream xstream = new XStreamGae();
>> String s = xstream.toXML(car);
>> Car c = (Car) xstream.fromXML(s);
>> }
>>
>>
>> The complete stack trace is here: http://pastebin.com/TGF6N17W
>>
>> The XStream related dependency in my application are:
>>
>> <dependency>
>> <groupId>com.thoughtworks.xstream</groupId>
>> <artifactId>xstream</artifactId>
>> <version>1.4.2</version>
>> </dependency>
>> <dependency>
>> <groupId>xpp3</groupId>
>> <artifactId>xpp3_min</artifactId>
>> <version>1.1.4c</version>
>> </dependency>
>
> Xpp3 is superfluous, since ...
>
>> <!-- XStreamGae Dependencies -->
>> <dependency>
>> <groupId>net.sf.kxml</groupId>
>> <artifactId>kxml2-min</artifactId>
>> <version>2.3.0</version>
>> </dependency>
>
> ... XStreamGae uses kXML2 instead.
>
>> <dependency>
>> <groupId>xmlpull</groupId>
>> <artifactId>xmlpull</artifactId>
>> <version>1.1.3.1</version>
>> </dependency>
>>
>> The XStreamGae class can be found here:
>>
>> http://www.wappworks.com/2011/11/11/using-xstream-with-google-app-engine/
>>
>> Is there a work-around to make this work-around work?
>
> No. As you can see, XStreamGae is explicitly initialized in pure Java mode,
> because the enhanced mode *cannot* work with GAE due to its security policy.
> You will have to add a no-arg constructor.
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>
>

So it means this will fail:

private Object newInstanceSkippingConstructor(final Class clazz) throws
SecurityException, NoSuchMethodException, IllegalArgumentException,
IllegalAccessException,     InvocationTargetException {

     Method newInstance =
ObjectInputStream.class.getDeclaredMethod("newInstance", Class.class,
Class.class);
     newInstance.setAccessible(true);
     return newInstance.invoke(null, clazz, Object.class);

}

?

-Xybrek


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: XStream and Google App Engine

Jörg Schaible-3
Hi,

Xybrek wrote:

[snip]
 

> So it means this will fail:
>
> private Object newInstanceSkippingConstructor(final Class clazz) throws
> SecurityException, NoSuchMethodException, IllegalArgumentException,
> IllegalAccessException,     InvocationTargetException {
>
>      Method newInstance =
> ObjectInputStream.class.getDeclaredMethod("newInstance", Class.class,
> Class.class);
>      newInstance.setAccessible(true);
>      return newInstance.invoke(null, clazz, Object.class);
>
> }
>
> ?

??

It fails because ObjectInputStream has no "newInstance" method. So what are
you trying to ask?

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email