How to deal with Class with filed whose type is Class ?

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

How to deal with Class with filed whose type is Class ?

by 许成子 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, All

Need your help. :)

For with filed whose type is Class like:

public class OArticle2 implements Serializable
{
    private static final long serialVersionUID = 1L;
    String name;
    Class classInfo = null;

    public OArticle2(String c, Class clazz)
    {
        name = c;
        classInfo = clazz;
    }
}

For one object of OArticle2, Xstream will serialize it into xml like:

<com.test.OArticle2>
  <name>Charles</name>
  <classInfo>com.test.changes.change1</classInfo>
</com.test.OArticle2 >

BUT, I want to know how to configure the Xstream to output the xml ??
like:

<com.test.OArticle2>
  <name>Charles</name>
  <classInfo>com.test.changes.v1000.change1</classInfo>
</com.test.OArticle2 >


Note:
 Here the classinfo is changed to com.test.changes.v1000.change1 from com.test.changes.change.
 I tried to configure xstream using aliasType or alias method, but it don't works.

The question is:

Is there API of xstream(1.3.1) to do this work to 'alias' the changed Class object to another Class object?

Thanks.

Best Regards
Charles

Re: How to deal with Class with filed whose type is Class ?

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

Reply to Author | View Threaded | Show Only this Message

Hi Charles,

Cheng-Zi Xu wrote at Dienstag, 8. September 2009 10:42:

> Hi, All
>
> Need your help. :)
>
> For with filed whose type is Class like:
>
> public class OArticle2 implements Serializable
> {
>     private static final long serialVersionUID = 1L;
>     String name;
>     Class classInfo = null;
>
>     public OArticle2(String c, Class clazz)
>     {
>         name = c;
>         classInfo = clazz;
>     }
> }
>
> For one object of OArticle2, Xstream will serialize it into xml like:
>
> <com.test.OArticle2>
>   <name>Charles</name>
>   <classInfo>com.test.changes.change1</classInfo>
> </com.test.OArticle2 >
>
> BUT, I want to know how to configure the Xstream to output the xml ??
> like:
>
> <com.test.OArticle2>
>   <name>Charles</name>
>   <classInfo>com.test.changes.v1000.change1</classInfo>
> </com.test.OArticle2 >
>
>
> Note:
>  Here the classinfo is changed to com.test.changes.v1000.change1 from
> com.test.changes.change.
>  I tried to configure xstream using aliasType or alias method, but it
>  don't
> works.
>
> The question is:
>
> Is there API of xstream(1.3.1) to do this work to 'alias' the changed
> Class object to another Class object?

What you see is the output of XStream's ClassConverter. It does not support
aliasing. You can create your own custom converter for Class types that do
this package renaming and register them as local converter for
Oarticle2.classInfo.

- Jörg


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

    http://xircles.codehaus.org/manage_email



Re: Re: How to deal with Class with filed whose type is Class ?

by 许成子 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, Jörg

Thanks for feedback, please see my response inline:

2009/9/9 Jörg Schaible <joerg.schaible@...>
Hi Charles,

Cheng-Zi Xu wrote at Dienstag, 8. September 2009 10:42:

> Hi, All
>
> Need your help. :)
>
> For with filed whose type is Class like:
>
> public class OArticle2 implements Serializable
> {
>     private static final long serialVersionUID = 1L;
>     String name;
>     Class classInfo = null;
>
>     public OArticle2(String c, Class clazz)
>     {
>         name = c;
>         classInfo = clazz;
>     }
> }
>
> For one object of OArticle2, Xstream will serialize it into xml like:
>
> <com.test.OArticle2>
>   <name>Charles</name>
>   <classInfo>com.test.changes.change1</classInfo>
> </com.test.OArticle2 >
>
> BUT, I want to know how to configure the Xstream to output the xml ??
> like:
>
> <com.test.OArticle2>
>   <name>Charles</name>
>   <classInfo>com.test.changes.v1000.change1</classInfo>
> </com.test.OArticle2 >
>
>
> Note:
>  Here the classinfo is changed to com.test.changes.v1000.change1 from
> com.test.changes.change.
>  I tried to configure xstream using aliasType or alias method, but it
>  don't
> works.
>
> The question is:
>
> Is there API of xstream(1.3.1) to do this work to 'alias' the changed
> Class object to another Class object?

What you see is the output of XStream's ClassConverter. It does not support
aliasing.

Yes. I understand. I trying to find this class (ClassConverter) in the source code of Xstreams. but it does not exist.
I want to learn from it and then write custom converter. could you provide the check the class name and provide it?
thanks.
 
You can create your own custom converter for Class types that do
this package renaming and register them as local converter for
Oarticle2.classInfo.

- Jörg


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

   http://xircles.codehaus.org/manage_email




Re: Re: How to deal with Class with filed whose type is Class ?

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

Reply to Author | View Threaded | Show Only this Message

Hi Charles,

Cheng-Zi Xu wrote at Donnerstag, 10. September 2009 07:56:

> Hi, Jörg
>
> Thanks for feedback, please see my response inline:
>
> 2009/9/9 Jörg Schaible <joerg.schaible@...>
>
>> Hi Charles,
>>
>> Cheng-Zi Xu wrote at Dienstag, 8. September 2009 10:42:
>>
>> > Hi, All
>> >
>> > Need your help. :)
>> >
>> > For with filed whose type is Class like:
>> >
>> > public class OArticle2 implements Serializable
>> > {
>> >     private static final long serialVersionUID = 1L;
>> >     String name;
>> >     Class classInfo = null;
>> >
>> >     public OArticle2(String c, Class clazz)
>> >     {
>> >         name = c;
>> >         classInfo = clazz;
>> >     }
>> > }
>> >
>> > For one object of OArticle2, Xstream will serialize it into xml like:
>> >
>> > <com.test.OArticle2>
>> >   <name>Charles</name>
>> >   <classInfo>com.test.changes.change1</classInfo>
>> > </com.test.OArticle2 >
>> >
>> > BUT, I want to know how to configure the Xstream to output the xml ??
>> > like:
>> >
>> > <com.test.OArticle2>
>> >   <name>Charles</name>
>> >   <classInfo>com.test.changes.v1000.change1</classInfo>
>> > </com.test.OArticle2 >
>> >
>> >
>> > Note:
>> >  Here the classinfo is changed to com.test.changes.v1000.change1 from
>> > com.test.changes.change.
>> >  I tried to configure xstream using aliasType or alias method, but it
>> >  don't
>> > works.
>> >
>> > The question is:
>> >
>> > Is there API of xstream(1.3.1) to do this work to 'alias' the changed
>> > Class object to another Class object?
>>
>> What you see is the output of XStream's ClassConverter. It does not
>> support aliasing.
>
>
> Yes. I understand. I trying to find this class (ClassConverter) in the
> source code of Xstreams. but it does not exist.

Sorry, the name is JavaClassConverter
(http://xstream.codehaus.org/javadoc/com/thoughtworks/xstream/converters/extended/JavaClassConverter.html),
an overview exists on the web site:
http://xstream.codehaus.org/converters.html

> I want to learn from it and then write custom converter. could you provide
> the check the class name and provide it?

Simply follow the converter tutorial, it's quite easy:
http://xstream.codehaus.org/converter-tutorial.html

- Jörg


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

    http://xircles.codehaus.org/manage_email



Re: Re: Re: How to deal with Class with filed whose type is Class ?

by 许成子 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, Jörg

Got it. Thanks very much! :)


2009/9/10 Jörg Schaible <joerg.schaible@...>
Hi Charles,

Cheng-Zi Xu wrote at Donnerstag, 10. September 2009 07:56:

> Hi, Jörg
>
> Thanks for feedback, please see my response inline:
>
> 2009/9/9 Jörg Schaible <joerg.schaible@...>
>
>> Hi Charles,
>>
>> Cheng-Zi Xu wrote at Dienstag, 8. September 2009 10:42:
>>
>> > Hi, All
>> >
>> > Need your help. :)
>> >
>> > For with filed whose type is Class like:
>> >
>> > public class OArticle2 implements Serializable
>> > {
>> >     private static final long serialVersionUID = 1L;
>> >     String name;
>> >     Class classInfo = null;
>> >
>> >     public OArticle2(String c, Class clazz)
>> >     {
>> >         name = c;
>> >         classInfo = clazz;
>> >     }
>> > }
>> >
>> > For one object of OArticle2, Xstream will serialize it into xml like:
>> >
>> > <com.test.OArticle2>
>> >   <name>Charles</name>
>> >   <classInfo>com.test.changes.change1</classInfo>
>> > </com.test.OArticle2 >
>> >
>> > BUT, I want to know how to configure the Xstream to output the xml ??
>> > like:
>> >
>> > <com.test.OArticle2>
>> >   <name>Charles</name>
>> >   <classInfo>com.test.changes.v1000.change1</classInfo>
>> > </com.test.OArticle2 >
>> >
>> >
>> > Note:
>> >  Here the classinfo is changed to com.test.changes.v1000.change1 from
>> > com.test.changes.change.
>> >  I tried to configure xstream using aliasType or alias method, but it
>> >  don't
>> > works.
>> >
>> > The question is:
>> >
>> > Is there API of xstream(1.3.1) to do this work to 'alias' the changed
>> > Class object to another Class object?
>>
>> What you see is the output of XStream's ClassConverter. It does not
>> support aliasing.
>
>
> Yes. I understand. I trying to find this class (ClassConverter) in the
> source code of Xstreams. but it does not exist.

Sorry, the name is JavaClassConverter
(http://xstream.codehaus.org/javadoc/com/thoughtworks/xstream/converters/extended/JavaClassConverter.html),
an overview exists on the web site:
http://xstream.codehaus.org/converters.html

> I want to learn from it and then write custom converter. could you provide
> the check the class name and provide it?

Simply follow the converter tutorial, it's quite easy:
http://xstream.codehaus.org/converter-tutorial.html

- Jörg


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

   http://xircles.codehaus.org/manage_email