How could I implement a "variant" class which would act as an adapter between Object and JAXB-natively-supported types?
I could then use Object in JAXB-annotated classes.
Therefor, I guess, I would need to store a type ID inside that adapter.
Any ideas?
NOTE: With "JAXB-natively-supported types" I mean types such as:
all primitive types, String
, Date
, byte[]开发者_StackOverflow社区
, List<any-JAXB-supported-type>
.
Usage Scenario
@XmlType
class SomeClass {
@XmlJavaTypeAdapter(VariantAdapter.class) // WITH OR WITHOUT?
@XmlElement
private Object somePrimitive = null;
// ...
}
Variant Class Idea Pseudocode
@XmlRootElement
@XmlType
class Variant {
@XmlAttribute
private final String typeID;
@XmlAttribute
private final String rawXML;
// ...
}
Adapter Class (Trivial)
class VariantAdapter extends XmlAdapter<Object, Variant> {
@Override
public Object marshal(VariantObject arg0) throws Exception {
// ...
}
@Override
public VariantObject unmarshal(Object arg0) throws Exception {
// ...
}
}
This existes already: See JAXBElement
Or for Collections and Map:
utils-apl-derived project
精彩评论