Using JavaBeanConverter

View: New views
6 Messages — Rating Filter:   Alert me  

Using JavaBeanConverter

by Jean-Philippe Steinmetz-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

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. 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 JavaBeanConverter

by Jörg Schaible-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi 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 constructor

by Unmesh joshi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi,

XStream by default constructs objects bypassing constructor. What is
the design rationale? Shouldn't constructors be respected?

Thanks,
Unmesh



New Windows 7: Simplify what you do everyday. Find the right PC for you.

Creating objects without calling constructor

by Unmesh joshi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi,

XStream by default constructs objects bypassing constructor. What is
the design rationale? Shouldn't constructors be respected?

Thanks,
Unmesh



Windows 7: Find the right PC for you. Learn more.

Re: Creating objects without calling constructor

by Jörg Schaible-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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



RE: Re: Creating objects without calling constructor

by Unmesh joshi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
makes sense. Thanks.

> 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.