如何将xml编组到jaxb包装类?

时间:2016-03-09 08:29:18

标签: java xml jaxb

<myresponse>
    <field1></field1>
    <field2></field2>
    //...
</myresponse>

@XmlRootElement(name = "myresponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class MyResponse {
    //fields
}

以下工作正常: JAXBContext jaxbContext = JAXBContext.newInstance(MyResponse.class);

问题:我想围绕该响应创建一个包装类,并将其编组到这个新类中。但是,如果XML结构保持不变呢?

public class CustomResponse {
    @XmlElement(name = "myresponse")
    private MyResponse myresponse;

    //some more DTO fields or bean logic
}

JAXBContext.newInstance(CustomResponse.class);

如果可能,我如何告诉jaxb实际将xml响应中的任何内容映射到@XmlElement(name = "myresponse")对象?

旁注:我无法控制收到的xml

0 个答案:

没有答案