MappingJackson2XmlHttpMessageConverter在编组期间创建额外/重复的xml元素

时间:2016-08-19 18:24:53

标签: spring-boot jaxb marshalling xjc

我正在使用xjc从xsd创建jaxb绑定类...并使用MappingJackson2XmlHttpMessageConverter将对象转换为xml ..但我所看到的是,当我在绑定文件中有一个列表时,转换器创建一个重复的xml元素..

XSD:

    

<xs:complexType name="orderSubmitType">
    <xs:all>
        <xs:element name="orderId" type="xs:string" />
        <xs:element name="giftCards" type="giftCards"/>

    </xs:all>
</xs:complexType>

<xs:complexType name="giftCards">
    <xs:sequence>
        <xs:element name="giftCard" type="giftCard"  minOccurs="0" maxOccurs="10"/>
    </xs:sequence>

</xs:complexType>

<xs:complexType name="giftCard">
    <xs:all>
        <xs:element name="cardNumber" type="xs:string" /> 
        <xs:element name="pinNumber" type="xs:string" /> 
    </xs:all>
</xs:complexType>   

JAVA:

公共类TestRestTemplateConfiguration {

public static RestTemplate getTestClientRestTemplate() {
    if (INSTANCE == null) {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setErrorHandler(new TestClientResponseErrorHandler());
        ClientHttpRequestInterceptor loggingInterceptor = new TestClientLoggingInterceptor();
        restTemplate.setInterceptors(Collections.singletonList(loggingInterceptor));
        restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));
       MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
        MappingJackson2XmlHttpMessageConverter jacksonXmlConverter = new MappingJackson2XmlHttpMessageConverter();
        restTemplate.setMessageConverters(Arrays.asList(jacksonConverter,jacksonXmlConverter));
        INSTANCE = restTemplate;
    }
    return INSTANCE;
}

}

创建的最终xml是..

<?xml version="1.0" encoding="UTF-8"?>
<OrderSubmitType>
   <orderId>111111</orderId>
   <giftCards>
      <giftCard>
         <giftCard>
            <cardNumber>123456790</cardNumber>
            <pinNumber>1111</pinNumber>
         </giftCard>
      </giftCard>
   </giftCards>
</OrderSubmitType>

你可以看到...还有一个额外的 <giftcard></giftcard>元素......

任何人都可以告诉我,我在做什么错误......

感谢...

0 个答案:

没有答案