У меня проблема с обработкой ответа API.Сначала я устанавливаю соединение, чтобы получить мой ответ:
HttpResponse<String> response = Unirest.get(buildUrl(newOrdersUrl)).basicAuth(login, pass).asString();
if(response.getStatus() == 200){
return OrdersConverter.convertOrders(response.getBody());
} else {
return null;
}
С:
public class OrdersConverter {
public static OrdersType convertOrders(String response) {
try {
JAXBContext jc = JAXBContext.newInstance(OrdersType.class);
Unmarshaller u = jc.createUnmarshaller();
StringBuffer xmlStr = new StringBuffer(response);
JAXBElement<OrdersType> o = u.unmarshal(new StreamSource(new StringReader(xmlStr.toString())), OrdersType.class);
return o.getValue();
} catch (JAXBException e) {
return null;
}
}
}
С этим https://sell.fruugo.com/fruugo-docs/fruugo-product-feed.xsd в качестве схемы
Мой ответ Строкавыглядит так (с отредактированной информацией)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<o:orders merchantId="Redacted" xmlns:o="https://www.fruugo.com/orders/schema">
<o:order>
<o:customerOrderId>Redacted</o:customerOrderId>
<o:orderId>Redacted</o:orderId>
<o:orderDate>Redacted</o:orderDate>
<o:orderReleaseDate>Redacted</o:orderReleaseDate>
<o:orderStatus>Redacted</o:orderStatus>
<o:customerLanguageCode>Redacted</o:customerLanguageCode>
<o:shippingAddress>
<o:firstName>Redacted</o:firstName>
<o:lastName>Redacted</o:lastName>
<o:streetAddress>Redacted</o:streetAddress>
<o:city>Redacted</o:city>
<o:province>Redacted</o:province>
<o:postalCode>Redacted</o:postalCode>
<o:countryCode>Redacted</o:countryCode>
<o:phoneNumber>Redacted</o:phoneNumber>
</o:shippingAddress>
<o:shippingMethod>Redacted</o:shippingMethod>
<o:shippingCostInclVAT>Redacted</o:shippingCostInclVAT>
<o:shippingCostVAT>Redacted</o:shippingCostVAT>
<o:orderLines>
<o:orderLine>
<o:productId>Redacted</o:productId>
<o:skuId>Redacted</o:skuId>
<o:skuName>Redacted</o:skuName>
<o:fruugoProductId>Redacted</o:fruugoProductId>
<o:fruugoSkuId>Redacted</o:fruugoSkuId>
<o:currencyCode>Redacted</o:currencyCode>
<o:itemPriceInclVat>Redacted</o:itemPriceInclVat>
<o:itemVat>Redacted</o:itemVat>
<o:totalPriceInclVat>Redacted</o:totalPriceInclVat>
<o:totalVat>Redacted</o:totalVat>
<o:vatPercentage>Redacted</o:vatPercentage>
<o:totalNumberOfItems>Redacted</o:totalNumberOfItems>
<o:pendingItems>Redacted</o:pendingItems>
<o:confirmedItems>Redacted</o:confirmedItems>
<o:shippedItems>Redacted</o:shippedItems>
<o:cancelledItems>Redacted</o:cancelledItems>
<o:returnAnnouncedItems>Redacted</o:returnAnnouncedItems>
<o:returnedItems>Redacted</o:returnedItems>
<o:itemsWithException>Redacted</o:itemsWithException>
</o:orderLine>
</o:orderLines>
</o:order>
<o:order>
<o:customerOrderId>Redacted</o:customerOrderId>
<o:orderId>Redacted</o:orderId>
<o:orderDate>Redacted</o:orderDate>
<o:orderReleaseDate>Redacted</o:orderReleaseDate>
<o:orderStatus>Redacted</o:orderStatus>
<o:customerLanguageCode>Redacted</o:customerLanguageCode>
<o:shippingAddress>
<o:firstName>Redacted</o:firstName>
<o:lastName>Redacted</o:lastName>
<o:streetAddress>Redacted</o:streetAddress>
<o:city>Redacted</o:city>
<o:province>Redacted</o:province>
<o:postalCode>Redacted</o:postalCode>
<o:countryCode>Redacted</o:countryCode>
<o:phoneNumber>Redacted</o:phoneNumber>
</o:shippingAddress>
<o:shippingMethod>Redacted</o:shippingMethod>
<o:shippingCostInclVAT>Redacted</o:shippingCostInclVAT>
<o:shippingCostVAT>Redacted</o:shippingCostVAT>
<o:orderLines>
<o:orderLine>
<o:productId>Redacted</o:productId>
<o:skuId>Redacted</o:skuId>
<o:skuName>Redacted</o:skuName>
<o:fruugoProductId>Redacted</o:fruugoProductId>
<o:fruugoSkuId>Redacted</o:fruugoSkuId>
<o:currencyCode>Redacted</o:currencyCode>
<o:itemPriceInclVat>Redacted</o:itemPriceInclVat>
<o:itemVat>Redacted</o:itemVat>
<o:totalPriceInclVat>Redacted</o:totalPriceInclVat>
<o:totalVat>Redacted</o:totalVat>
<o:vatPercentage>Redacted</o:vatPercentage>
<o:totalNumberOfItems>Redacted</o:totalNumberOfItems>
<o:pendingItems>Redacted</o:pendingItems>
<o:confirmedItems>Redacted</o:confirmedItems>
<o:shippedItems>Redacted</o:shippedItems>
<o:cancelledItems>Redacted</o:cancelledItems>
<o:returnAnnouncedItems>Redacted</o:returnAnnouncedItems>
<o:returnedItems>Redacted</o:returnedItems>
<o:itemsWithException>Redacted</o:itemsWithException>
</o:orderLine>
</o:orderLines>
</o:order>
<o:order>
<o:customerOrderId>Redacted</o:customerOrderId>
<o:orderId>Redacted</o:orderId>
<o:orderDate>Redacted</o:orderDate>
<o:orderReleaseDate>Redacted</o:orderReleaseDate>
<o:orderStatus>Redacted</o:orderStatus>
<o:customerLanguageCode>Redacted</o:customerLanguageCode>
<o:shippingAddress>
<o:firstName>Redacted</o:firstName>
<o:lastName>Redacted</o:lastName>
<o:streetAddress>Redacted</o:streetAddress>
<o:city>Redacted</o:city>
<o:province>Redacted</o:province>
<o:postalCode>Redacted</o:postalCode>
<o:countryCode>Redacted</o:countryCode>
<o:phoneNumber>Redacted</o:phoneNumber>
</o:shippingAddress>
<o:shippingMethod>Redacted</o:shippingMethod>
<o:shippingCostInclVAT>Redacted</o:shippingCostInclVAT>
<o:shippingCostVAT>Redacted</o:shippingCostVAT>
<o:orderLines>
<o:orderLine>
<o:productId>Redacted</o:productId>
<o:skuId>Redacted</o:skuId>
<o:skuName>Redacted</o:skuName>
<o:fruugoProductId>Redacted</o:fruugoProductId>
<o:fruugoSkuId>Redacted</o:fruugoSkuId>
<o:currencyCode>Redacted</o:currencyCode>
<o:itemPriceInclVat>Redacted</o:itemPriceInclVat>
<o:itemVat>Redacted</o:itemVat>
<o:totalPriceInclVat>Redacted</o:totalPriceInclVat>
<o:totalVat>Redacted</o:totalVat>
<o:vatPercentage>Redacted</o:vatPercentage>
<o:totalNumberOfItems>Redacted</o:totalNumberOfItems>
<o:pendingItems>Redacted</o:pendingItems>
<o:confirmedItems>Redacted</o:confirmedItems>
<o:shippedItems>Redacted</o:shippedItems>
<o:cancelledItems>Redacted</o:cancelledItems>
<o:returnAnnouncedItems>Redacted</o:returnAnnouncedItems>
<o:returnedItems>Redacted</o:returnedItems>
<o:itemsWithException>Redacted</o:itemsWithException>
</o:orderLine>
</o:orderLines>
</o:order>
</o:orders>
Когда я конвертирую этот ответ в OrdersType.class, я могу получить свой merchantID, но не получаю Список заказов из OrdersType.class.Чего мне не хватает?Нужно ли преобразовывать этот ответ в другой класс, чтобы получить список заказов?
ОБНОВЛЕНИЕ:
ObjectFactory
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the model package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _Orders_QNAME = new QName("https://www.fruugo.com/orders/schema", "orders");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: model
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link ShippingAddressType }
*
*/
public ShippingAddressType createShippingAddressType() {
return new ShippingAddressType();
}
/**
* Create an instance of {@link OrderLinesType }
*
*/
public OrderLinesType createOrderLinesType() {
return new OrderLinesType();
}
/**
* Create an instance of {@link OrderType }
*
*/
public OrderType createOrderType() {
return new OrderType();
}
/**
* Create an instance of {@link ShipmentLinesType }
*
*/
public ShipmentLinesType createShipmentLinesType() {
return new ShipmentLinesType();
}
/**
* Create an instance of {@link ShipmentType }
*
*/
public ShipmentType createShipmentType() {
return new ShipmentType();
}
/**
* Create an instance of {@link ShipmentsType }
*
*/
public ShipmentsType createShipmentsType() {
return new ShipmentsType();
}
/**
* Create an instance of {@link ShipmentLineType }
*
*/
public ShipmentLineType createShipmentLineType() {
return new ShipmentLineType();
}
/**
* Create an instance of {@link AttributeType }
*
*/
public AttributeType createAttributeType() {
return new AttributeType();
}
/**
* Create an instance of {@link AttributesType }
*
*/
public AttributesType createAttributesType() {
return new AttributesType();
}
/**
* Create an instance of {@link OrdersType }
*
*/
public OrdersType createOrdersType() {
return new OrdersType();
}
/**
* Create an instance of {@link OrderLineType }
*
*/
public OrderLineType createOrderLineType() {
return new OrderLineType();
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link OrdersType }{@code >}}
*
*/
@XmlElementDecl(namespace = "https://www.fruugo.com/orders/schema", name = "orders")
public static JAXBElement<OrdersType> createOrders(OrdersType value) {
return new JAXBElement<OrdersType>(_Orders_QNAME, OrdersType.class, null, value);
}
}
OrdersType
<code>/**
* <p>Java class for OrdersType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="OrdersType">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="order" type="{https://www.fruugo.com/orders/schema}OrderType" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* <attribute name="version" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="merchantId" type="{http://www.w3.org/2001/XMLSchema}string" />
* </restriction>
* </complexContent>
* </complexType>
*
* ** / @XmlAccessorType (XmlAccessType.FIELD) @XmlType (name = "OrdersType", propOrder = {"order"}) открытый класс OrdersType {защищенный список order;@XmlAttribute (name = "version") защищенная версия String;@XmlAttribute (name = "merchantId") защищенный String merchantId;/ ** * Получает значение свойства заказа.* *
* Этот метод доступа возвращает ссылку на текущий список, * не снимок.Поэтому любые изменения, которые вы вносите в возвращаемый список *, будут присутствовать внутри объекта JAXB.* Вот почему нет метода set
для свойства заказа.* *
* Например, чтобы добавить новый элемент, выполните следующие действия: *
* getOrder().add(newItem);
*
* * *
* Объекты следующих типов разрешены в списке * {@link OrderType} ** * / public List getOrder () {if (order == null) {order = new ArrayList ();} return this.order;} / ** * Получает значение свойства версии.* * @return * возможным объектом является * {@link String} * * / public String getVersion () {return version;} / ** * Устанавливает значение свойства version.* * @param value * допустимым объектом является * {@link String} * * / public void setVersion (String value) {this.version = value;} / ** * Получает значение свойства merchantId.* * @return * возможным объектом является * {@link String} * * / public String getMerchantId () {return merchantId;} / ** * Устанавливает значение свойства merchantId.* * @param value * допустимым объектом является * {@link String} * * / public void setMerchantId (String value) {this.merchantId = value;}}
OrderType
<code>/**
* <p>Java class for OrderType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="OrderType">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="orderId" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="orderDate" type="{http://www.w3.org/2001/XMLSchema}dateTime"/>
* <element name="orderReleaseDate" type="{http://www.w3.org/2001/XMLSchema}dateTime"/>
* <element name="orderStatus" type="{https://www.fruugo.com/orders/schema}OrderStatusEnumType"/>
* <element name="customerLanguageCode" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="shippingAddress" type="{https://www.fruugo.com/orders/schema}ShippingAddressType"/>
* <element name="shippingMethod" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="shippingCostInclVAT" type="{http://www.w3.org/2001/XMLSchema}float"/>
* <element name="shippingCostVAT" type="{http://www.w3.org/2001/XMLSchema}float"/>
* <element name="orderLines" type="{https://www.fruugo.com/orders/schema}OrderLinesType"/>
* <element name="shipments" type="{https://www.fruugo.com/orders/schema}ShipmentsType" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
*
* * * / @XmlAccessorType (XmlAccessType.FIELD) @XmlType (name = "OrderType", propOrder = {"orderId", "orderDate", "orderReleaseDate "," orderStatus "," customerLanguageCode "," shippingAddress "," shippingMethod "," shippingCostInclVAT "," shippingCostVAT "," orderLines "," shipments "}) открытый класс OrderType {@XmlElement (required = true) защищенный String orderId;@XmlElement (обязательно = true) @XmlSchemaType (name = "dateTime") защищенный XMLGregorianCalendar orderDate;@XmlElement (обязательно = правда) @XmlSchemaType (name = "dateTime") защищенный XMLGregorianCalendar orderReleaseDate;@XmlElement (обязательно = true) protected OrderStatusEnumType orderStatus;@XmlElement (обязательный = true) защищенный String customerLanguageCode;@XmlElement (обязательно = true) защищенный ShippingAddressType shippingAddress;@XmlElement (обязательно = true) защищенный String shippingMethod;защищенный поплавок shippingCostInclVAT;защищенный поплавок shippingCostVAT;@XmlElement (обязательно = true) защищенный OrderLinesType orderLines;защищенные отгрузки Тип доставки;/ ** * Получает значение свойства orderId.* * @return * возможным объектом является * {@link String} * * / public String getOrderId () {return orderId;} / ** * Устанавливает значение свойства orderId.* * @param value * допустимым объектом является * {@link String} * * / public void setOrderId (String value) {this.orderId = value;} / ** * Получает значение свойства orderDate.* * @return * возможным объектом является * {@link XMLGregorianCalendar} * * / public XMLGregorianCalendar getOrderDate () {return orderDate;} / ** * Устанавливает значение свойства orderDate.* * @param value * допустимым объектом является * {@link XMLGregorianCalendar} * * / public void setOrderDate (XMLGregorianCalendar value) {this.orderDate = value;} / ** * Получает значение свойства orderReleaseDate.* * @return * возможным объектом является * {@link XMLGregorianCalendar} * * / public XMLGregorianCalendar getOrderReleaseDate () {return orderReleaseDate;} / ** * Устанавливает значение свойства orderReleaseDate.* * @param value * допустимым объектом является * {@link XMLGregorianCalendar} * * / public void setOrderReleaseDate (XMLGregorianCalendar value) {this.orderReleaseDate = value;} / ** * Получает значение свойства orderStatus.* * @return * возможный объект: * {@link OrderStatusEnumType} * * / public OrderStatusEnumType getOrderStatus () {return orderStatus;} / ** * Устанавливает значение свойства orderStatus.* * @param value * допустимым объектом является * {@link OrderStatusEnumType} * * / public void setOrderStatus (OrderStatusEnumType value) {this.orderStatus = value;} / ** * Получает значение свойства customerLanguageCode.* * @return * возможным объектом является * {@link String} * * / public String getCustomerLanguageCode () {return customerLanguageCode;} / ** * Устанавливает значение свойства customerLanguageCode.* * @param value * допустимым объектом является * {@link String} * * / public void setCustomerLanguageCode (String value) {this.customerLanguageCode = value;} / ** * Получает значение свойства shippingAddress.* * @return * возможным объектом является * {@link ShippingAddressType} * * / public ShippingAddressType getShippingAddress () {return shippingAddress;} / ** * Устанавливает значение свойства shippingAddress.* * @param value * допустимым объектом является * {@link ShippingAddressType} * * / public void setShippingAddress (ShippingAddressType value) {this.shippingAddress = value;} / ** * Получает значение свойства shippingMethod.* * @return * возможным объектом является * {@link String} * * / public String getShippingMethod () {return shippingMethod;} / ** * Устанавливает значение свойства shippingMethod.* * @param value * допустимым объектом является * {@link String} * * / public void setShippingMethod (String value) {this.shippingMethod = value;} / ** * Получает значение свойства shippingCostInclVAT.* * / public float getShippingCostInclVAT () {return shippingCostInclVAT;} / ** * Устанавливает значение свойства shippingCostInclVAT.* * / public void setShippingCostInclVAT (значение с плавающей запятой) {this.shippingCostInclVAT = value;} / ** * Получает значение свойства shippingCostVAT.* * / public float getShippingCostVAT () {return shippingCostVAT;} / ** * Устанавливает значение свойства shippingCostVAT.* * / public void setShippingCostVAT (значение с плавающей точкой) {this.shippingCostVAT = значение;} / ** * Получает значение свойства orderLines.* * @return * возможным объектом является * {@link OrderLinesType} * * / public OrderLinesType getOrderLines () {return orderLines;} / ** * Устанавливает значение свойства orderLines.* * @param value * допустимым объектом является * {@link OrderLinesType} * * / public void setOrderLines (OrderLinesType value) {this.orderLines = value;} / ** * Получает значение свойства отправлений.* * @return * возможный объект: * {@link ShipmentsType} * * / public ShipmentsType getShipments () {возврат отправлений;} / ** * Устанавливает значение свойства shipments.* * @param value * допустимым объектом является * {@link ShipmentsType} * * / public void setShipments (ShipmentsType value) {this.shipments = value;}}