Java 使用Jackson序列化具有名为value的属性的XML元素

Java 使用Jackson序列化具有名为value的属性的XML元素,java,xml-parsing,jackson,jaxb,jackson2,Java,Xml Parsing,Jackson,Jaxb,Jackson2,我正在尝试使用下面的元素反序列化xml内容 <?xml version="1.0" encoding="utf-8" ?> <confirmationConditions> <condition type="NM-GD" value="something">no modification of guest details</condition> </confirmationConditions> 错误 基本上我想要的是将元素内

我正在尝试使用下面的元素反序列化xml内容

<?xml version="1.0" encoding="utf-8" ?>
<confirmationConditions>
    <condition type="NM-GD" value="something">no modification of guest details</condition>
</confirmationConditions>
错误


基本上我想要的是将元素内容映射到
text
字段。我无法控制xml,因此更改它对我不起作用。

这里需要添加@JacksonXmlText

class Condition {
    @JacksonXmlProperty(isAttribute = true)
    private String type;
    @JacksonXmlProperty(isAttribute = true)
    private String value;
    @JacksonXmlText
    private String text;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
}
并以这种方式进行分析:

    JacksonXmlModule module = new JacksonXmlModule();
    module.setDefaultUseWrapper(false);
    XmlMapper xmlMapper = new XmlMapper(module);

    xmlMapper.readValue(
            "<condition type=\"NM-GD\" value=\"something\">no modification of guest details</condition>", Condition.class);
JacksonXmlModule模块=新的JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper XmlMapper=新的XmlMapper(模块);
xmlMapper.readValue(
“不修改客人详细信息”,条件类);

这里需要添加@JacksonXmlText

class Condition {
    @JacksonXmlProperty(isAttribute = true)
    private String type;
    @JacksonXmlProperty(isAttribute = true)
    private String value;
    @JacksonXmlText
    private String text;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
}
并以这种方式进行分析:

    JacksonXmlModule module = new JacksonXmlModule();
    module.setDefaultUseWrapper(false);
    XmlMapper xmlMapper = new XmlMapper(module);

    xmlMapper.readValue(
            "<condition type=\"NM-GD\" value=\"something\">no modification of guest details</condition>", Condition.class);
JacksonXmlModule模块=新的JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper XmlMapper=新的XmlMapper(模块);
xmlMapper.readValue(
“不修改客人详细信息”,条件类);