Inner Text and child elements

前端 未结 1 530
旧时难觅i
旧时难觅i 2020-12-20 20:32

I would like to deserialize XML like the following using JAXB in Java:



    
           


        
相关标签:
1条回答
  • 2020-12-20 21:34

    This is called "mixed-mode content", and it's generally a pain in the ass to process.

    The key in JAXB is to use the @XmlMixed annotation - see javadoc.

    Try something like this:

    @XmlRootElement(name = "container") 
    static class Container {
        @XmlMixed 
        @XmlElementRefs({
                @XmlElementRef(name="foo", type=Foo.class)
        })
        List<?> content;
    
        // ... plus the usual getters/setters
    }
    

    The content list should contain a sequence of Foo objects and Strings.

    0 讨论(0)
提交回复
热议问题