|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Using JavaBeanConverterHello everyone, I’ve got a bean class that I want to use the
JavaBeanConverter on. I’ve set up the following converter for my xstream: xstream.registerConverter(new JavaBeanConverter(xstream.getMapper()) { @SuppressWarnings({"unused", "unchecked"}) public boolean canHandle(Class
type) { return MyBean.class.isAssignableFrom(type); } }); The problem I am
seeing is that it converts all the child properties of a MyBean object with the
bean converter as well. What I want, however, is to only convert objects that
are of type MyBean. If the MyBean object contains a property of a different non-MyBean
type (i.e. java.util.Date) it should use the standard converter instead. How do
I do this? Thanks in
advance, Jean-Philippe |
|
|
Re: Using JavaBeanConverterHi Jean-Phillipe,
Jean-Philippe Steinmetz wrote: > Hello everyone, > > > > I've got a bean class that I want to use the JavaBeanConverter on. I've > set up the following converter for my xstream: > > > > xstream.registerConverter(new JavaBeanConverter(xstream.getMapper()) { > > @SuppressWarnings({"unused", "unchecked"}) > > public boolean canHandle(Class type) { > > return MyBean.class.isAssignableFrom(type); > > } > > }); > > > > The problem I am seeing is that it converts all the child properties of > a MyBean object with the bean converter as well. Normally not. > What I want, however, > is to only convert objects that are of type MyBean. If the MyBean object > contains a property of a different non-MyBean type (i.e. java.util.Date) > it should use the standard converter instead. How do I do this? This will work by default. However, you have to implement this anonymous type correctly. Add the @Override annotation to your method and you will know what I mean :)) - Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Creating objects without calling constructorHi, Unmesh New Windows 7: Simplify what you do everyday. Find the right PC for you. |
|
|
Creating objects without calling constructorHi, Unmesh Windows 7: Find the right PC for you. Learn more. |
|
|
Re: Creating objects without calling constructorHi Umesh,
Unmesh joshi wrote: > > Hi, > > XStream by default constructs objects bypassing constructor. What is > the design rationale? Behave like Java serialization. > Shouldn't constructors be respected? No. XStream simply reconstructs the original object graph and running constructor code can have unpredictable side effects making this impossible. Therefore Java serialization does not run constructors either. - Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
RE: Re: Creating objects without calling constructor> To: user@... > From: joerg.schaible@... > Date: Tue, 27 Oct 2009 20:01:56 +0100 > Subject: [xstream-user] Re: Creating objects without calling constructor > > Hi Umesh, > > Unmesh joshi wrote: > > > > > Hi, > > > > XStream by default constructs objects bypassing constructor. What is > > the design rationale? > > Behave like Java serialization. > > > Shouldn't constructors be respected? > > No. XStream simply reconstructs the original object graph and running > constructor code can have unpredictable side effects making this > impossible. Therefore Java serialization does not run constructors either. > > - Jörg > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > Windows 7: Find the right PC for you. Learn more. |
| Free embeddable forum powered by Nabble | Forum Help |