Quantcast

How to use public accessor instead of field?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to use public accessor instead of field?

Jarod Liu
I know since version 1.1.2 , xstream support using public accessors instead of fields. but i can't find any example in doucment to find out how to do this.

--
刘远志
QQ:2065254
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: How to use public accessor instead of field?

Jörg Schaible
Hi 刘远志,
________________________________

        From: liuyuanzhi AT gmail.com
        Sent: Wednesday, June 28, 2006 6:26 AM
        Subject: [xstream-user] How to use public accessor instead of field?
       
       
        I know since version 1.1.2 , xstream support using public accessors instead of fields. but i can't find any example in doucment to find out how to do this.
       
        --
        刘远志
        QQ:2065254

________________________________

I am not sure, what you are really referring to, but you might refer the JavaBeanConverter ... do you?

- Jörg
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to use public accessor instead of field?

Jarod Liu
version 1.1.2 major change states this:
"XSTR-186, Option to serialize JavaBeans using public accessors, rather than private fields (contributed by Andrea Aime)."



what i want is xstream just serializes properties that have a getter method. and kick other private fields out.
i don't know how to do this.


On 6/28/06, Jörg Schaible <[hidden email]> wrote:
Hi 刘远志,
________________________________

        From: liuyuanzhi AT gmail.com
        Sent: Wednesday, June 28, 2006 6:26 AM
        Subject: [xstream-user] How to use public accessor instead of field?


        I know since version 1.1.2 , xstream support using public accessors instead of fields. but i can't find any example in doucment to find out how to do this.

        --
        刘远志
        QQ:2065254

________________________________

I am not sure, what you are really referring to, but you might refer the JavaBeanConverter ... do you?

- Jörg



--
刘远志
QQ:2065254
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: How to use public accessor instead of field?

Jörg Schaible
In reply to this post by Jarod Liu
Hi 刘远志,

________________________________

        From: liuyuanzhi AT gmail.com
        Sent: Wednesday, June 28, 2006 8:56 AM
        Subject: Re: [xstream-user] How to use public accessor instead of field?
       
       
        version 1.1.2 major change states this:
        "XSTR-186 <http://jira.codehaus.org/browse/XSTR-186> , Option to serialize JavaBeans using public accessors, rather than private fields (contributed by Andrea Aime)."
       
       
       
        what i want is xstream just serializes properties that have a getter method. and kick other private fields out.
        i don't know how to do this.
       
________________________________

This is off by default, since XStream uses normally a converter based on reflection. You have to register a JavaBeanConverter with a priority equals or one better than this reflection based converter. See unit test as an example:

http://fisheye.codehaus.org/browse/xstream/tags/XSTREAM_1_1_3/xstream/src/test/com/thoughtworks/xstream/converters/javabean/JavaBeanConverterTest.java?r=554

If you want this behaviour only for certain types instead for all classes, you have to derive from the JavaBeanConverter and adjust the canConvert method accordingly.

- Jörg
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to use public accessor instead of field?

Jarod Liu
thank you very much. the unit test is a good example for me.

On 6/28/06, Jörg Schaible <[hidden email]> wrote:
Hi 刘远志,

________________________________

        From: liuyuanzhi AT gmail.com
        Sent: Wednesday, June 28, 2006 8:56 AM
        Subject: Re: [xstream-user] How to use public accessor instead of field?


        version 1.1.2 major change states this:
        "XSTR-186 <http://jira.codehaus.org/browse/XSTR-186> , Option to serialize JavaBeans using public accessors, rather than private fields (contributed by Andrea Aime)."



        what i want is xstream just serializes properties that have a getter method. and kick other private fields out.
        i don't know how to do this.

________________________________

This is off by default, since XStream uses normally a converter based on reflection. You have to register a JavaBeanConverter with a priority equals or one better than this reflection based converter. See unit test as an example:

http://fisheye.codehaus.org/browse/xstream/tags/XSTREAM_1_1_3/xstream/src/test/com/thoughtworks/xstream/converters/javabean/JavaBeanConverterTest.java?r=554

If you want this behaviour only for certain types instead for all classes, you have to derive from the JavaBeanConverter and adjust the canConvert method accordingly.

- Jörg



--
刘远志
QQ:2065254
Loading...