Wednesday, 7 January 2015

Marshal an object as one of its properties with JAXB (as for value objects i.e primitive types wrappers)



I got a class like



public class Name {
private String value;

public String getValue(){...}
public void setValue(String value){...}
}


used as in



public class Person{

@XmlElement(name = "IDName")
public Name getName(){...}
}


I'd like to marshal Name object as the value of it's identity property. How can I achieve that?



<Person>
<IDName>foo</IDName>
</Person>


instead of



<Person>
<IDName>
<Value>foo</Value>
</IDName>
</Person>


I'd tried both to indicate in Person that Name object should be marshalled as itself.getValue() and either to indicate within Name class to marshal without any element wrapper (its fields directly) with no luck.


No comments:

Post a Comment