Jorg, Jaime,
Thanks for your time, thanks for your responses.
I did try also registering JavaBeanConverter. The result was unexpected;
String properties weren't serialized. Just Strings were omitted, the other
types, boolean, Boolean, user defined types, were serialized as usual.
I compared the serialization from 1.3.1 to 1.4.2, the diff shows:
4c4
< <abbrev>ABG</abbrev>
---
> <abbrev/>
where 'abbrev' is a String property; the data hasn't changed. And so on,
there are many String properties, in many objects, as far as I can tell
none are serialized as they were previously.
I tried configuring XStream in various ways, the simplest is as follows:
xstream = new XStream() {
protected MapperWrapper wrapMapper(final MapperWrapper next) {
return new HibernateMapper(next);
}
};
xstream.registerConverter(new
JavaBeanConverter(xstream.getMapper()));
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()));
Admittedly I'm not sure if this is correct. I didn't see anything similar
in the test code that comes with the source distribution. I've tried
various configurations without success.
Thanks,
Michael
On Tue, May 8, 2012 at 6:20 PM, Jaime Metcher <[email protected]> wrote:
> I seem to recall that the @Transient annotation is used by XStream to mark
> properties to be omitted. Obviously it's a JPA annotation as well. But
> I'm not sure that this is something new in 1.4.2
>
> Jaime
>
> On Wed, May 9, 2012 at 5:41 AM, Michael Teixeira <
> [email protected]> wrote:
>
>> 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
>>
>>
>