Andreas Sachs | 13 May 02:41
Picon
Picon

Jettison upgrade changes json

Hi,
after upgrading xstream from 1.3.1 to 1.4.2 and jettison 1.0.1 to 1.2 (or 1.3.1) the generated json string
changed. I could also change the javascript processing of the json string, but the new version looks
strange to me.

I try to serialize the following object tree:

class userlist {
	private List<User> users;
}

class User {
	private name;
	private vorname;
}

After the upgrade the json string contains collections at two different levels.

Old
{"userlist":{"users":{"user":[{"name":"x","vorname":"y"},{"name":"x","vorname":"y"}]}}}

New
{"userlist":{"users":[{"user":[{"name":"x","vorname":"y"},{"name":"x","vorname":"y"}]}]}}

Is this ok and i should change my code? or is this a bug?

Thanks
Andi

---------------------------------------------------------------------
(Continue reading)

Pablo Pazos | 11 May 02:58
Picon
Gravatar

Customizing JSON Map serialization

Hi,


I'm trying to serialize to JSON an object that has a HashMap field, the output is something like this:

"originalAuthor": [
            [
              "organisation",
              "Ocean Informatics"
            ],
            [
              "name",
              "Chunlan Ma"
            ],
            [
              "date",
              "16/11/2006"
            ]
          ]

But I expected something more like a JSON object:

"originalAuthor": {
              "organisation": "Ocean Informatics",
              "name": "Chunlan Ma",
              "date": "16/11/2006"
          }

This is a simple example, field values can be complex objects.


Is there some way of generating a structure like this for Map Java objects?

Thanks a lot.

--
Atte.
Ing. Pablo Pazos Gutiérrez
LinkedIn: http://uy.linkedin.com/in/pablopazosgutierrez
Blog: http://informatica-medica.blogspot.com/
Sígueme en twitter: http://twitter.com/ppazos
Michael Teixeira | 8 May 21:41
Picon

configuring HibernateProxyConverter

As part of going from xstream 1.3.1 to xstream 1.4.2, I'm trying to make use of HibernateProxyConverter.

So I've changed the xstream configuration from, in 1.3.1:

        this.xstream = new XStream();
        xstream.registerConverter(new JavaBeanConverter(xstream.getMapper()), XStream.PRIORITY_VERY_LOW);
        Mapper mapper = xstream.getMapper();
        xstream.registerConverter(new HibernateCollectionConverter(mapper));
        xstream.addDefaultImplementation(java.util.ArrayList.class, org.hibernate.collection.PersistentList.class);
        xstream.addDefaultImplementation(java.util.HashMap.class, org.hibernate.collection.PersistentMap.class);
        xstream.addDefaultImplementation(java.util.HashSet.class, org.hibernate.collection.PersistentSet.class);
        xstream.addDefaultImplementation(java.util.ArrayList.class, org.hibernate.collection.PersistentBag.class);
        xstream.alias("java.util.ArrayList", org.hibernate.collection.PersistentBag.class);

to, in 1.4.2:

        xstream = new XStream() {
            protected MapperWrapper wrapMapper(final MapperWrapper next) {
                return new HibernateMapper(next);
            }
        };
        xstream.registerConverter(new HibernateProxyConverter());
        xstream.registerConverter(new HibernatePersistentCollectionConverter(xstream.getMapper()));
        xstream.registerConverter(new HibernatePersistentMapConverter(xstream.getMapper()));
        xstream.registerConverter(new HibernatePersistentSortedMapConverter(xstream.getMapper()));
        xstream.registerConverter(new HibernatePersistentSortedSetConverter(xstream.getMapper()));

That more or less seems to work, with this exception:

I have a java class that represents a relational table that is being serialized by xstream.  But this class has some transient properties along with the usual persistent properties that map to database columns.

Some of these transient properties are also java classes that I've defined.  Something simple like a class that holds a name and value with a getter and setter.

In my prior code, using xstream 1.3.1 and JavaBeanConverter, these contained class instances were serialized and deserialized without issue.  In the 1.4.2 code, though, these properties are not serialized, they are omitted.

So it would seem that HibernateProxyConverter does not handle these.

I've been trying, without success, to add a second converter to handle these.  I'm not sure that's the correct approach, though.  In general, I could use some help, or guidance, on how best to do this.

Thanks,
Michael

Ajaya Sahoo | 4 May 05:34
Picon
Favicon

How do I get the coorect value for XML special characters

Hi,
 
I have an element with the following value ( <condition> a > b </condition> ). When I put the value in the object and use Xstream.toXML the value comes <condition> a &gt; b</condition>. How to get back the exact string with > character?
 
Thanks,
ajaya
Walton, Lynn | 30 Apr 21:39
Picon
Favicon

deserializing json with numbered object names

Hello all,

I'm hoping to use XStream with the JettisonMappedXmlDriver to deserialize some 3rd party json output.

The json output includes numbers  as object names so in my example below propertyC actually has 3 nested
objects but uses a number "1", "2", or "3" as the object name.  In my real world the json usually contains
between 100 and 200 of these (it varies).

For instance:

{ "root" : { "propertyA " : "valueA",
      "propertyB" : "valueB",
      "propertyC" : { "1" : { "propertyC1" : "propertyC1_1_Value",
              "propertyC2" : "propertyC2_1_Value",
              "propertyC3" : "propertyC3_1_Value"
            },
          "2" : { "propertyC1" : "propertyC1_2_Value",
              "propertyC2" : "propertyC2_2_Value",
              "propertyC3" : "propertyC3_2_Value"
            },
          "3" : { "propertyC1" : "propertyC1_3_Value",
              "propertyC2" : "propertyC2_3_Value",
              "propertyC3" : "propertyC3_3_Value"
            }
        },
      "propertyD" : "valueD"
    } }

Can someone point me in the direction of what I'd have to do to make this work so that I could have the json
deserialized into Java objects.  I thought I'd have the  Root object with it's simple properties/fields
for propertyA, propertyB, and propertyD and a collection of propertyC but then I don't know how to
configure a converter and/or aliases to handle the "1", "2","3" , etc all as the same object.  I'd like to
build 3 objects of the same type and where it has an extra property that really represents the object name
(the 1, 2 or 3, etc).

Are there some advance aliasing, converter  and/or other tricks I could use to make this reasonable with
xstream and jettison or should I look into other json converting utilities?  I don't want to "preprocess"
the json string to change its format.

Thanks!

Lynn Walton
Java Web Developer
ADP Digital Marketing Solutions
p 850.897.9467 | e lynn.walton@...<mailto:lynn.walton@...>
[cid:image001.gif@...]<http://adpdealerservices.com/>[cid:image002.gif@...]<http://cobalt.com/>[cid:image003.gif <at> 01CD26DB.5E7E6F10]<http://bzresults.com/>[cid:image004.gif@...]<http://cobalt.com/dealix/>
This message and any attachments are intended only for the use of the addressee and may contain information
that is privileged and confidential. If the reader of the message is not the intended recipient or an
authorized representative of the intended recipient, you are hereby notified that any dissemination of
this communication is strictly prohibited. If you have received this communication in error, please
notify us immediately by email and delete the message and any attachments from your system.

This message and any attachments are intended only for the use of the addressee and may contain information
that is privileged and confidential. If the reader of the message is not the intended recipient or an
authorized representative of the intended recipient, you are hereby notified that any dissemination of
this communication is strictly prohibited. If you have received this communication in error, please
notify us immediately by e-mail and delete the message and any attachments from your system.
Amit Basu | 29 Apr 21:31
Picon
Favicon

get rid of class="list" for more than one contained List interface fields

I have a container class as follows:

class FruitBasket {
 List<Apple> apples;
 List<Orange> oranges;
}

I have added xstream.registerConverter(new HibernatePersistentCollectionConverter(xstream.getMapper()));
I have also setup alias apple for com.myorg.Apple and com.myorg.Orange.

The marshalled FruitBasket object has:

<apples class="list">
  <apple>....</apple>
  <apple>....</apple>
</apples>
<oranges class="list">
  <orange>....</orange>
  <orange>....</orange>
</oranges>

In order to get rid of the class="list" in apples and oranges, I added 
xstream.alias("apples", List.class, PersistentList.class);
xstream.alias("oranges", List.class, PersistentList.class);
 
The objects are marshalled all right, without the class= attributes.

But the client unmarshals, and fails with com.thoughtworks.xstream.mapper.CannotResolveClassException: oranges 

If I change the order of aliasing with oranges first instead of apples:
xstream.alias("oranges", List.class, PersistentList.class);
xstream.alias("apples", List.class, PersistentList.class);

then the CannotResolveClassException comes for apples.

Seems like at most one collection of the same interface type (List in this case) is end-to-end marshalled / unmarshalled all right for the FruitBasket container class.

I would like to know if there is a way around the problem.

Jirka Hana | 22 Apr 23:10
Picon

Class with an interface field saved as an id

Hello,

 I am new to XStream, I got 95% of my task done in nearly no time, but now I am stuck with trying to serialize the following class:

class MyClass {
    private String name;
    private Pattern pattern;
    // few more fields 
    
    private ColumnPrinter<?> printer;  
}

The printer can be an instance of any subclass (possibly anonymous) of the ColumnPrinter interface. All must implement the getId() method and all are registered in a global registry (by calling the method ColumnPrinter<?> getPrinter(String id))

I would like to save all the fields the usual way, but for the printer, I would like to save its id only (say as <printer>12</printer>). Then when deserializing the id should be read, and the proper instance should be looked up in the global registry. 

I am not sure how to do that. Can anybody help?

Thanks
Jirka

    
    
satya | 18 Apr 18:34
Picon

IS XStream also Thread Safe while configured through Spring OXM

Hi

http://xstream.codehaus.org/faq.html - says XStream is thread safe -
"Once the XStream instance has been created and configured, it may be
shared across multiple threads "

    XStream xstream = new XStream();
    Person person = (Person)xstream.fromXML(xml);

 So above piece of code should work fine in multi-threaded environment :

Coming to the Point -
I use Spring OXM ,where i can configure Marshaller/Unmarshaller in any of
the following ways :

<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound"> ....
                             OR
<bean id="xstreamMarshaller"
class="*org.springframework.oxm.xstream.XStreamMarshaller*">
     <property name="aliases"> ......

   import *org.springframework.oxm.Marshaller*;
   import *org.springframework.oxm.Unmarshaller*;
   public class Application {
   private *Marshaller *marshaller;
   private *Unmarshaller *unmarshaller;

IS XStream also Thread Safe while configured through Spring-OXM(as above) ?

If so , then can we say org.springframework.oxm.*Marshaller *&
org.springframework.oxm.*Unmarshaller *also Thread Safe ? OR it depends on
the kind of marshaller (jaxbMarshaller/xstreamMarshaller) configured
through Spring OXM .

Clarification will be helpful . Thanks

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

    http://xircles.codehaus.org/manage_email

Mahesh | 17 Apr 21:32
Picon
Favicon

Class cast exception while instantiate converter

Hi

I am getting the below exception while converting XML to object. I am using 
Xstream 1.4.1 and JDK 1.6.

It's working fine in one websphere server (RAD 7.5 and websphere 7.0) and it's 
not working in another websphere server 7.0.

Please tell me the reason, why i am getting the below exception.

com.thoughtworks.xstream.XStream$InitializationException: Could not instantiate 
converter : com.thoughtworks.xstream.converters.extended.DurationConverter : 
null
 at com.thoughtworks.xstream.XStream.dynamicallyRegisterConverter
(XStream.java:732)
 at com.thoughtworks.xstream.XStream.setupConverters(XStream.java:696)
 at com.thoughtworks.xstream.XStream.<init>(XStream.java:445)
 at com.thoughtworks.xstream.XStream.<init>(XStream.java:385)
 at com.thoughtworks.xstream.XStream.<init>(XStream.java:342)
... 39 more
Caused by: 
java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:56)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:39)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
 at com.thoughtworks.xstream.XStream.dynamicallyRegisterConverter
(XStream.java:725)
 ... 46 more
Caused by: 
java.lang.ClassCastException: 
org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl incompatible with 
javax.xml.datatype.DatatypeFactory
 at javax.xml.datatype.DatatypeFactory.newInstance(Unknown Source)
 at com.thoughtworks.xstream.converters.extended.DurationConverter.<init>
(DurationConverter.java:33)
 ... 51 more

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

    http://xircles.codehaus.org/manage_email

nino martinez wael | 13 Apr 11:23
Picon
Gravatar

HashMap containing unknown values

Hi 


I am having some difficulties making xstream intrepret the xml that are being delivered to me.

In short on the java side I want to have a hashmap<string,string> containing entities inside the xml tag called log, the attributes on info are wildcard (the sender of the xml can write whatever he wants)

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<HttpInfo>
           
<NetCoolLogLevel>0</NetCoolLogLevel>
           
<Log>
                         
<Info id="1-LI031" status="OK"/>
                         
<Info id="2-LI031" status="OK"/>
            </Log>
           
<DocLink></DocLink>
           
<DocInfo></DocInfo>
</HttpInfo>

This is what I've got:

Initial loading:

Java (with annotations) for classes:

Current XML(working):

Specified XML:




--
Best regards / Med venlig hilsen 
Nino Martinez

Amit Basu | 11 Apr 04:32
Picon
Favicon

XStreamMarshaller does not unproxy at marshalling

I use a org.springframework.http.converter.xml.MarshallingHttpMessageConverter with org.springframework.oxm.xstream.XStreamMarshaller as marshaller/unmarshaller.

With default-lazy=false hibernate-mapping, org.springframework.web.client.RestTemplate.getForObject() works fine.

But with default-lazy = true, some contained objects from the top-level object are org.hibernate.proxy.pojo.javassist.SerializableProxy, which makes the getForObject() fail, with org.hibernate.LazyInitializationException- could not initialize proxy - no Session

Is there a way to get the marshaller to initialize and unproxy as needed, when writing to the stream ?

I want to have the same API calls for REST and non-REST situations (non-REST = local JVM calls that can make further calls with the Hibernate session, to get contents from proxies as needed), and ideally default-lazy = true is preferred for non-REST calls, but then if the same call is used by a REST controller, the marshalling keeps the proxies as is currently.

Gmane