Question on serialization

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Question on serialization

Abhiram Panyam
I would like to know if I can serialize methods in addition to fields. For
instance, I have the following class

public class offerVO {

        private Long offerId;
        private String offer;

        public OfferVO() {

        }

        public Long getOfferId() {
                return offerId;
        }

        public void setOfferId(Long offerId) {
                this.offerId = offerId;
        }

        public String getOffer() {
                return offer;
        }

        public void setOffer(String offer) {
                this.offer = offer;
        }

        public Date getExpirationDate() {
           return Calendar.getInstance().getDate();
        }
}

Notice that there is no field called expirationDate in the class, but I
would like to have it appear in the XML as an attribute called
'expirationDate' for the OfferVO element. Please advise.

Thanks,
abhi


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Question on serialization

Jörg Schaible-2
Hi Abhi,

Abhiram Panyam wrote:

> I would like to know if I can serialize methods in addition to fields. For
> instance, I have the following class
>
> public class offerVO {
>
>         private Long offerId;
> private String offer;
>
>         public OfferVO() {
>
>         }
>
>         public Long getOfferId() {
> return offerId;
> }
>
> public void setOfferId(Long offerId) {
> this.offerId = offerId;
> }
>
> public String getOffer() {
> return offer;
> }
>
> public void setOffer(String offer) {
> this.offer = offer;
> }
>
>         public Date getExpirationDate() {
>            return Calendar.getInstance().getDate();
>         }
> }
>
> Notice that there is no field called expirationDate in the class, but I
> would like to have it appear in the XML as an attribute called
> 'expirationDate' for the OfferVO element. Please advise.

You can register a JavaBeanConverter to handle OfferVO:

JavaBeanProvider beanProvider = new JavaBeanProvider();
xstream.registerConverter(new JavaBeanConverter(xstream.getMapper(),
beanProvider, OfferVO.class));

Cheers,
Jörg


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Question on serialization

Abhiram Panyam


Jörg Schaible <joerg.schaible@...> writes:

> Hi Abhi,
>
> You can register a JavaBeanConverter to handle OfferVO:
>
> JavaBeanProvider beanProvider = new JavaBeanProvider();
> xstream.registerConverter(new JavaBeanConverter(xstream.getMapper(),
> beanProvider, OfferVO.class));
>
>

Hi Jorg:

It appears JavaBeanProvider is an interface. I can't create an object of its
type using the 'new' operator. Are there any methods that return a
JavaBeanProvider ?

Thanks,
abhi


Reply | Threaded
Open this post in threaded view
|

Re: Question on serialization

Jörg Schaible-4
Hi Abhi,

Abhiram Panyam wrote:

>
>
> Jörg Schaible <joerg.schaible@...> writes:
>
>> Hi Abhi,
>>
>> You can register a JavaBeanConverter to handle OfferVO:
>>
>> JavaBeanProvider beanProvider = new JavaBeanProvider();
>> xstream.registerConverter(new JavaBeanConverter(xstream.getMapper(),
>> beanProvider, OfferVO.class));
>>
>>
>
> Hi Jorg:
>
> It appears JavaBeanProvider is an interface. I can't create an object of
> its type using the 'new' operator. Are there any methods that return a
> JavaBeanProvider ?

BeanProvider

Cheers,
Jörg


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

    http://xircles.codehaus.org/manage_email