【问题标题】:Serializing with JAXB and the Any (without ElementNS)使用 JAXB 和 Any(没有 ElementNS)进行序列化
【发布时间】:2015-07-25 01:41:26
【问题描述】:

我正在寻找一个最佳实践来编组一个可以处理字符串、长等的 XMLAnyElement...我找到了一个 Serializing with JAXB and the Any,但我需要避免使用 ElementNS 并解决附加的案例

DOMHandler 是不是最好的方法?

public static void main(String[] args) throws JAXBException {
    JAXBContext jc = JAXBContext.newInstance(Payload.class, Foo.class, ObjectFactory.class);

    Payload payload = new Payload();
    payload.any = new ArrayList<>();
    payload.any.add(new Bar());
    payload.any.add(new Foo());
    payload.any.add("pepe"); 

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(payload, System.out);
}

【问题讨论】:

标签: jaxb


【解决方案1】:

已解决,在github上查看我的PoC..

https://github.com/franciscophilip/jaxb-payload-poc/

【讨论】:

    猜你喜欢
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多