Can I change the field name

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

Can I change the field name

rushit patel-2

Say i had a class
 
class Person{
public String name;
 
Person(){
name ="xxxxxx";
}
public static void main(String[] args){
 
XStream xStream = new XStream(new DomDriver());
System.out.println(xStream.toXml(new Person()));
 
  }
} 
 
It give output
---------------------------------------------------------------------------------------------------------------------
<person>
 <name>xxxxxx</name>
</person>
---------------------------------------------------------------------------------------------------------------------


but if i want output like

---------------------------------------------------------------------------------------------------------------------
<person>
 <first-name>xxxxxx</first-name>
</person>
---------------------------------------------------------------------------------------------------------------------
i dont want to change my field name of Person class

How to achive this!!!!



 


Reply | Threaded
Open this post in threaded view
|

Re: Can I change the field name

Jörg Schaible-2
Hi Rushit,

rushit patel wrote:

[snip]
 
> It give output
>
---------------------------------------------------------------------------------------------------------------------
> <person>
>  <name>xxxxxx</name>
>  </person>
>
>
---------------------------------------------------------------------------------------------------------------------
>
>
> but if i want output like
>
>
>
---------------------------------------------------------------------------------------------------------------------
> <person>
>  <first-name>xxxxxx</first-name>
>  </person>
>
>
---------------------------------------------------------------------------------------------------------------------
> i dont want to change my field name of Person class
>
> How to achive this!!!!

Set an alias for the field name.

- Jörg