杰克逊泽西JAXB缺少序幕

时间:2016-04-29 23:48:27

标签: jaxb jersey jackson

我正在开发一个小应用程序,其中包括jersey,jackson和jaxb。我正在尝试生成如下的xml输出:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Customers xmlns="http://www.example.com/platform/customer/v1">
    <customer>
        <text>customer name</text>
    </customer>
</Customers>

但我得到的是:

<Customers xmlns="http://www.example.com/platform/customer/v1">
    <customer xmlns="">
        <text>customer name</text>
    </customer>
</Customers>

所以主要是缺少xm prologue并附加带有客户标签的xmlns。 这是我的POJO:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Customers", namespace = "http://www.example.com/platform/customers/v1")
public class CustomersDTO  {

    @JsonProperty("customer")
    @JacksonXmlElementWrapper(useWrapping = false)
    private List<CustomerDTO> customers;

    public CustomersDTO() {

    }

    public List<CustomerDTO> getCustomers() {
        return this.customers;
    }

    public void setCustomers(List<CustomerDTO> customers) {
        this.customers = customers;
    }


}

这是我如何使用xmlmapper设置jersey客户端

this.setXmlMapper(new XmlMapper());

this.getXmlMapper().registerModule(new JaxbAnnotationModule());
this.getXmlMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
this.getXmlMapper().configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
this.getXmlMapper().configure(SerializationFeature.INDENT_OUTPUT, true);
this.getXmlMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
this.getXmlMapper().configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
this.getXmlMapper().findAndRegisterModules();

任何建议我在这里可能缺少什么。在此先感谢

最佳Sajid

0 个答案:

没有答案