Spring RestTemplate忽略package-info.java

时间:2018-05-24 13:28:36

标签: java xml spring xsd jaxb

我使用' xjc'从xsd生成了一些类。命令。

我遇到的问题是,在生成的包中有一个package-info文件,包中只包含@XmlSchema注释:

e.g。

@javax.xml.bind.annotation.XmlSchema(namespace = "https://plazaapi.bol.com/services/xsd/v2/plazaapi.xsd", elementFormDefault = XmlNsForm.QUALIFIED)
package com.xxx.bolapp.dto;

我遇到两个问题:首先,编组人员在解组时总是抛出异常:

exception is org.springframework.http.converter.HttpMessageNotReadableException: Could not unmarshal to [class nl.minc.bolapp.dto.Orders]: unexpected element (uri:"https://plazaapi.bol.com/services/xsd/v2/plazaapi.xsd", local:"Orders"). Expected elements are <{}Orders>; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"https://plazaapi.bol.com/services/xsd/v2/plazaapi.xsd", local:"Orders"). Expected elements are <{}Orders>

我可以直接在@XmlRoot上设置名称空间时删除它 一旦我这样做,初始订单就会被正确解析。我遇到的问题是,孩子们都是空的,应该有数据。

现在的问题主要是孩子是空的,但我怀疑它与命名空间有关。

编辑1 发布命名空​​间时,null子项的问题消失了 在每个XmlElement中,这绝对是一个直接的因果关系。

我发布了生成的类和xml:

类别:

package com.xxx.bolapp.dto;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "order"
})
@XmlRootElement(name = "Orders")
public class Orders
    implements Serializable
{

    private final static long serialVersionUID = 1L;
    @XmlElement(name = "Order")
    protected List<Orders.Order> order;
....
    @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "orderId",
    "dateTimeCustomer",
    "dateTimeDropShipper",
    "customerDetails",
    "orderItems"
})
public static class Order
    implements Serializable
{
....
}
}

XML:

<?xml version="1.0" encoding="UTF-8"?>
<Orders xmlns="https://plazaapi.bol.com/services/xsd/v2/plazaapi.xsd">
<Order>
 <OrderId>4123456789</OrderId>
 <DateTimeCustomer>2017-02-09T12:39:48.000+01:00</DateTimeCustomer>
 <DateTimeDropShipper>2017-02-09T12:39:48.000+01:00</DateTimeDropShipper>
 <CustomerDetails>
   <ShipmentDetails>
     <SalutationCode>02</SalutationCode>
     <Firstname>Billie</Firstname>
     <Surname>Van der Bol.com</Surname>
     <Streetname>Dorpstraat</Streetname>
     <Housenumber>1</Housenumber>
     <HousenumberExtended>B</HousenumberExtended>
     <ZipCode>1111 ZZ</ZipCode>
     <City>Utrecht</City>
     <CountryCode>NL</CountryCode>
     <Email>2awq74td4z4mizmx6dcdbsdbdcna@verkopen.bol.com</Email>
     <Company>bol.com</Company>
   </ShipmentDetails>
   <BillingDetails>
     <SalutationCode>02</SalutationCode>
     <Firstname>Billie</Firstname>
     <Surname>van der Bol.com</Surname>
     <Streetname>Dorpstraat</Streetname>
     <Housenumber>1</Housenumber>
     <HousenumberExtended>B</HousenumberExtended>
     <ZipCode>1111 ZZ</ZipCode>
     <City>Utrecht</City>
     <CountryCode>NL</CountryCode>
     <Email>2awq74td4z4mizmx6dcdbsdbdcna@verkopen.bol.com</Email>
     <Company>bol.com</Company>
   </BillingDetails>
 </CustomerDetails>
 <OrderItems>
   <OrderItem>
     <OrderItemId>2012345678</OrderItemId>
     <EAN>5412810182312</EAN>
     <OfferReference>BOLCOM00123</OfferReference>
     <Title>Basicxl - Rijdende Wekker - Kunststof - 16x11cm - Zwart</Title>
     <Quantity>1</Quantity>
     <OfferPrice>27.95</OfferPrice>
     <TransactionFee>5.18</TransactionFee>
     <LatestDeliveryDate>2017-02-10+01:00</LatestDeliveryDate>
     <OfferCondition>NEW</OfferCondition>
     <CancelRequest>false</CancelRequest>
     <FulfilmentMethod>FBR</FulfilmentMethod>
   </OrderItem>
 </OrderItems>
 </Order>
</Orders>

0 个答案:

没有答案