开发者

JAXB: How to implement a JAXB-compatible variant wrapper class?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜