Reputation: 6649
EDIT: Previous answer does not work (it stills create a nested object) I'm using Jersey and Jackson.
I got a class like
@XmlAccessorType(XmlAccessType.NONE)
public class Name {
private String value;
@XmlValue
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.
Upvotes: 3
Views: 451
Reputation: 6649
A possible solution is replacing @XmlValue annotation with Jackson's @JsonValue to make it work (tested). I infer from http://wiki.fasterxml.com/JacksonJAXBAnnotations that it can be the only solution for now
According to this the official documentation
@javax.xml.bind.annotation.XmlValue
The field/property to which this annotation is applied will be named "value".
So maybe it's limited by design. Any better answer, specially if using JAXB annotations alone, will be much appreciated
Upvotes: 1