I have this situation
@XmlType(name ="", propOrder={"value"})
@XmlRootElement(name = "compound")
public class Compound extends Value {
@XmlElements({
@XmlElement(name="simple", type=Simple.class),
@XmlElement(name="compound", type=Compound.class)
})
protected List<Value> value;
// ...
}
So a Compound is a List of both Simple and/or Compound. Both extend from Value that is defined as
public abstract class Value implements Serializable {}
Simple is a class marked with an adapter to marshal/unmarshal to/from a simple string
@XmlJavaTypeAdapter(SimpleAdapter.class)
public class Simple extends Value {
private java.lang.String simple;
// ...
}
Compound does not need an adapter.
The problem is that if I use a Simple 'as is', it correctly marshals/unmarshals as
<simple>my.text.here</simple>
but if I use it inside a Compound it outputs something like
<compound>
//...
<simple>
<value>my.text.here</value>
</simple>
//...
</compound>
And I'm just wondering why... Do I miss something? How can i remove that 'value'? It seems to me that the Adapter is not used at all, is it possible to use adapters in types marked inside @XmlElements?
EDIT
After few tests i found that the problem could be in how i handle a Simple instance. So I simplify my initial question in:
Given the a Simple class like
@XmlRootElement("simple")
public class Simple {
private java.lang.String innerText;
// getters/setters
}
how can i obtain a marshalled output like
<simple>
my.inner.text.here
</simple>
instead of
<simple>
<value>my.inner.text.here</value>
</simple>
?
Compound
andSimple
inherit fromValue
, but that isn't reflected in their definitions. – BigamistCompound
is<simple><value>my.text.here</value></simple>
and not<simple><simple>my.text.here</simple></simple>
? I would understand the latter, but I don't see why would the former happen. Where's thevalue
element name defined? – Bigamist