Getting an exception with parsing from json to pojo - throws mismatched exception : Cannot deserialize instance of `double` out of START_OBJECT token
我试着把它列成单子,但没用。将其启用为arraylist也不起作用。请任何人指出问题并提出正确的方法。
另外,我在这里单独给出了json,但在代码中,我将json硬编码为字符串。仅供参考
JSON -
{
"orderExtendAttribute": [
{
"attributeName": "shipModeUpdatedByUser",
"attributeValue": "1",
"attributeType": "string"
},
{
"attributeName": "recieveOrderSMS",
"attributeValue": "0",
"attributeType": "String"
},
{
"attributeName": "ORDER_CONFIRMATION_XML_SENT_STATUS",
"attributeValue": "1"
},
{
"attributeName": "ORDER_CONFIRMATION_EMAIL_SENT_STATUS",
"attributeValue": "1"
}
],
"x_isPersonalAddressesAllowedForShipping": "true",
"recordSetComplete": "true",
"x_address_addressLine1": "Block 36, Palk Street, Cannaught Place",
"totalAdjustment": "-8.68000",
"placedDate": "2021-03-01T15:20:02.012Z",
"x_address_firstName": "Pawan",
"resourceId": "https://uwcs400.academy.com:443/wcs/resources/store/10151/order/450259009",
"x_billing_address_zipCode": "72601",
"x_shipToStoreCharge": "0",
"totalProductPrice": "19.99000",
"x_payment_method": "PLCC",
"storeNameIdentifier": "Academy",
"x_totalShippingCharge": "0.00000",
"x_address_phoneNumber": "8888456234",
"resourceName": "order",
"buyerDistinguishedName": "uid=rehehi6645@bulkbye.com,o=default organization,o=root organization",
"totalShippingCharge": "7.68000",
"totalShippingChargeCurrency": "USD",
"grandTotal": "20.56000",
"x_address_present": "Y",
"x_totalAdjustment": "-1.00000",
"orderStatus": "M",
"x_trackingIds": "",
"totalProductPriceCurrency": "USD",
"x_totalTax": "1.57000",
"x_billing_address_country": "US",
"x_address_addressId": "306911",
"x_billing_address_addressId": "306913",
"locked": "false",
"x_hasFireArm02Items": "false",
"x_receiveEmail": "1",
"recordSetTotal": "1",
"storeUniqueID": "10151",
"recordSetCount": "1",
"totalSalesTaxCurrency": "USD",
"x_address_zipCode": "77001",
"orderItem": [
{
"unitQuantity": "1.0",
"unitPrice": "19.99000",
"phone2": "",
"totalAdjustment": {
"value": "-8.68000",
"currency": "USD"
},
"phone1": "8888456234",
"addressId": "306911",
"city": "Houston",
"xitem_shippingType": "SG",
"phone2Publish": "true",
"fulfillmentCenterName": "Academy",
"postalCode": "77001",
"orderItemInventoryStatus": "Allocated",
"shippingTax": "0.00000",
"nickName": "20210301070251103",
"zipCode": "77001",
"orderItemStatus": "M",
"carrier": "FEDX",
"contractId": "4000000000000000002",
"quantity": "1.0",
"unitUom": "C62",
"salesTax": "1.57000",
"middleName": "",
"lastName": "Jaiswal",
"isExpedited": "false",
"orderItemFulfillmentStatus": "Unreleased",
"shipModeCode": "FEDX Home",
"shippingCharge": "7.68000",
"country": "US",
"shipModeId": "11359",
"orderItemId": "450968009",
"organizationName": "",
"state": "TX",
"usableShippingChargePolicy": [
{
"name": "StandardShippingChargeBySeller",
"uniqueID": "-7001",
"type": "ShippingCharge"
}
],
"currency": "USD",
"addressLine": [
"Block 36, Palk Street, Cannaught Place",
"",
""
],
"availableDate": "2021-03-01T15:20:00.488Z",
"stateOrProvinceName": "TX",
"adjustment": [
{
"amount": "-1.00000",
"xiadju_skuPartNumber": "120993553",
"description": "Academy Sports + Outdoors Credit Card Discount",
"usage": "Discount",
"language": "-1",
"code": "PLCC_EveryDay5-816389107",
"xiadju_skuName": "Magellan Outdoors Men's Casting Crew Long Sleeve Fishing Shirt",
"currency": "USD"
},
{
"amount": "-7.68000",
"xiadju_skuPartNumber": "120993553",
"description": "Academy Sports + Outdoors Credit Card Free Standard Shipping on over $15",
"usage": "Shipping Adjustment",
"language": "-1",
"code": "PLCC_Free_Shipping-816389109",
"xiadju_skuName": "Magellan Outdoors Men's Casting Crew Long Sleeve Fishing Shirt",
"currency": "USD"
}
],
"shippingChargeCurrency": "USD",
"orderItemPrice": "19.99000",
"phone1Publish": "true",
"fax2": "",
"fulfillmentCenterId": "10051",
"fax1": "",
"firstName": "Pawan",
"createDate": "2021-03-01T15:18:58.745Z",
"correlationGroup": "450968009",
"salesTaxCurrency": "USD",
"partNumber": "123349472",
"orderItemExtendAttribute": [
{
"attributeName": "estimatedFromDate",
"attributeValue": "2021-03-05",
"attributeType": "string"
},
{
"attributeName": "estimatedToDate",
"attributeValue": "2021-03-08",
"attributeType": "string"
}
],
"freeGift": "false",
"xitem_isPersonalAddressesAllowedForShipping": "true",
"shipModeDescription": "FEDX Home",
"xitem_parentCatentryId": "7700611",
"email1": "",
"shipModeLanguage": "-1",
"email2": "",
"lastUpdateDate": "2021-03-01T15:20:02.012Z",
"productId": "8199018",
"shippingTaxCurrency": "USD",
"offerID": "4000000000009006659",
"personTitle": "",
"UOM": "C62",
"expectedShipDate": "2021-03-03T06:07:30.912Z"
}
],
"x_address_city": "Houston",
"totalShippingTax": "0.00000",
"x_promoApplied": "true",
"x_cvv_present": "Y",
"x_hasFireArm": "false",
"x_billing_address_phoneNumber": "8888345213",
"adjustment": [
{
"amount": "-1.00000",
"xadju_calUsageId": "-1",
"xadju_longDescription": "<p><span class=\"left\" style=\"color: rgb(0, 0, 0); font-size: 10pt; font-family: Arial;\">Academy Sports + Outdoors Credit Card Discount</span></p>\n\n<table>\n</table>\n",
"displayLevel": "Order",
"description": "Academy Sports + Outdoors Credit Card Discount",
"usage": "Discount",
"code": "PLCC_EveryDay5-816389107",
"descriptionLanguage": "-1",
"currency": "USD"
},
{
"amount": "-7.68000",
"xadju_calUsageId": "-7",
"xadju_longDescription": "<p><span style=\"font-family:calibri,sans-serif;\"><span style=\"font-size:11.0pt;\">Academy Sports + Outdoors Credit Card Free Standard Shipping on over $15</span></span></p>\n",
"displayLevel": "Order",
"description": "Academy Sports + Outdoors Credit Card Free Standard Shipping on over $15",
"usage": "Shipping Adjustment",
"code": "PLCC_Free_Shipping-816389109",
"descriptionLanguage": "-1",
"currency": "USD"
}
],
"x_address_lastName": "Jaiswal",
"x_field3": "206.222.171.33",
"grandTotalCurrency": "USD",
"paymentInstruction": [
{
"piDescription": "Academy Private Credit Card",
"xpaym_policyId": "10670",
"organizationName": "",
"state": "AR",
"phone2": "",
"phone1": "8888345213",
"billing_address_id": "306913",
"city": "Harrison",
"addressLine": [
"514 SANSING HOLLOW RD ",
"",
""
],
"stateOrProvinceName": "AR",
"phone2Publish": "true",
"postalCode": "72601",
"nickName": "2021030107025110320210301091932",
"zipCode": "72601",
"phone1Publish": "true",
"fax2": "",
"fax1": "",
"firstName": "Pawan",
"piStatus": "Success",
"middleName": "",
"lastName": "Jaiswal",
"protocolData": [
{
"name": "IxReceiptDisplay",
"value": "Approved "
},
{
"name": "IxAuthTime",
"value": "2021-03-01T09:20:00"
},
{
"name": "IxActionCode",
"value": "0"
},
{
"name": "cardHolderLastName",
"value": "Jaiswal"
},
{
"name": "IxAuthResponseTime",
"value": "0"
},
{
"name": "IxIsoResp",
"value": "000"
},
{
"name": "tokenEx",
"value": "Y"
},
{
"name": "cardType",
"value": "PLCC"
},
{
"name": "IxAmount",
"value": "2056"
},
{
"name": "billing_address_id",
"value": "306913"
},
{
"name": "IxDebitComLink",
"value": "00500009"
},
{
"name": "IxOptions",
"value": "privatelabel *STORESTAN 10742 *Tokenization *AvsResp-Y "
},
{
"name": "token",
"value": "2514227113120384"
},
{
"name": "IxNeedsReversal",
"value": "1200&amp;#x1C;010742&amp;#x1C;210301092000&amp;#x1C;000000002056&amp;#x1C;001030"
},
{
"name": "IxAuthCode",
"value": "001030"
},
{
"name": "payment_method",
"value": "PLCC"
},
{
"name": "cardHolderFirstName",
"value": "Pawan"
},
{
"name": "lastFourCCDigit",
"value": "0384"
}
],
"piCurrency": "USD",
"xpaym_punchoutPayment": "false",
"payMethodId": "PLCC",
"email1": "rehehi6645@bulkbye.com",
"email2": "",
"country": "US",
"xpaym_tokenization": "false",
"piLanguage": "-1",
"piAmount": "20.56000",
"piId": "183008",
"personTitle": ""
}
],
"x_isPurchaseOrderNumberRequired": "false",
"x_address_state": "TX",
"orderId": "450259009",
"shipAsComplete": "false",
"totalShippingTaxCurrency": "USD",
"x_billing_address_state": "AR",
"orderTypeCode": "ORD",
"recordSetStartNumber": "0",
"x_billing_address_lastName": "Jaiswal",
"x_isAPGPAvailable": "true",
"x_billing_address_addressLine1": "514 SANSING HOLLOW RD ",
"x_field2": "99.00000",
"x_orderRemainingAmount": "0.00000",
"totalSalesTax": "1.57000",
"buyerId": "866023",
"lastUpdateDate": "2021-03-01T15:20:02.012Z",
"x_billing_address_city": "Harrison",
"x_billing_address_firstName": "Pawan",
"x_billing_address_present": "Y",
"prepareIndicator": "true",
"totalAdjustmentCurrency": "USD",
"channel": {
"description": {
"value": "Used when operations performed from a desktop browser.",
"language": "-1"
},
"userData": null,
"channelIdentifer": {
"channelName": "Web Channel",
"uniqueID": "-1"
}
},
"x_billing_address_email": "rehehi6645@bulkbye.com"
}
//要填充的目标类
package com.pr;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConfirmedOrderResponseVo {
private List<OrderExtendAttribute> orderExtendAttribute;
private int recordSetTotal;
private String totalSalesTaxCurrency;
private double totalAdjustment;
private String totalShippingTax;
private double totalProductPrice;
private String grandTotalCurrency;
private String orderId;
private String totalShippingTaxCurrency;
private String totalShippingCharge;
private String specialOrderShipToStoreCharge;
private List<Payment> payments;
private int recordSetStartNumber;
private String totalShippingChargeCurrency;
private String grandTotal;
private double totalSalesTax;
private String orderStatus;
private String totalProductPriceCurrency;
private String totalAdjustmentCurrency;
private boolean hasAgeRestrictedItems;
private JsonNode promotionCode;
private boolean hasSOFItems;
private List<OrderLevelAdjustment> orderLevelAdjustments;
private int langId;
private int catalogId;
private String orderTypeCode;
private String totalTax;
private String employeeDiscount;
private String billingAddressPresent;
private String billingAddressFirstName;
private String billingAddressLastName;
private String billingAddressAptName;
private String billingAddressLine;
private String billingAddressEmail;
private String billingAddressId;
private String billingAddressPhoneNumber;
private String billingAddressZipCode;
private String billingAddressCity;
private String billingAddressState;
private String billingAddressCompanyName;
private String billingAddressCountry;
private JsonNode totals;
private List<OrderItem> orderItem;
private JsonNode shippingGroups;
private JsonNode addresses;
private JsonNode promoDetails;
private List<OrderItem> bundleProductDetails = new ArrayList<>();
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class OrderLevelAdjustment{
String amount ;
String displayLevel;
String usage;
String code;
String currency;
String description;
String longDescription;
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown=true)
public static class Payment{
private String addressId;
private String firstName;
private String lastName;
private List<String> addressLine;
private String zipCode;
private String city;
private String state;
private String country;
private String phoneNumber;
private String organizationName;
private String emailId;
private String amount;
private String id;
private String gcBalance;
private List<ProtocolData> protocolData = new ArrayList<>();
}
public AddressVo getBillingAddress() {
if(payments!=null && payments.get(0)!=null) {
Payment paymentObj = payments.stream()
.filter(paymentMethod -> !paymentMethod.getProtocolData().stream()
.anyMatch(data1 -> "Gift Card".equalsIgnoreCase(data1.getValue())))
.findFirst().orElse((this.getPayments().size() >= 1) ? this.getPayments().get(0) : null);
if(paymentObj!=null && paymentObj.addressId!=null && paymentObj.addressLine!=null && paymentObj.addressLine.get(0)!=null
&& paymentObj.zipCode!=null && !paymentObj.addressLine.get(0).isEmpty() && !paymentObj.zipCode.isEmpty()
&& !paymentObj.addressId.isEmpty()) {
String addressLineStr = paymentObj.addressLine.get(0);
if(paymentObj.addressLine.size() > 1 && paymentObj.addressLine.get(1)!=null) {
addressLineStr = paymentObj.addressLine.get(0) +" , " + paymentObj.addressLine.get(1);
}
return new AddressVo(paymentObj.addressId, paymentObj.firstName, paymentObj.lastName,
addressLineStr, null, paymentObj.zipCode, paymentObj.city, paymentObj.state,
paymentObj.country, paymentObj.phoneNumber, paymentObj.organizationName,
paymentObj.emailId,null);
} else if(paymentObj != null && (paymentObj.addressId == null || paymentObj.addressLine == null)
&& StringUtils.isNotEmpty(billingAddressPresent) && billingAddressPresent.equalsIgnoreCase("Y") && StringUtils.isNotEmpty(billingAddressLine)) {
return billingAdessForNextGen();
}
}
return null;
}
private AddressVo billingAdessForNextGen() {
String addressLineStr = billingAddressLine;
if(StringUtils.isNotEmpty(billingAddressAptName)) {
addressLineStr = billingAddressLine + " , " + billingAddressAptName;
}
return new AddressVo(billingAddressId, billingAddressFirstName, billingAddressLastName,
addressLineStr, null, billingAddressZipCode, billingAddressCity, billingAddressState,
billingAddressCountry, billingAddressPhoneNumber, billingAddressCompanyName,
billingAddressEmail,null);
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ProtocolData{
private String name;
private String value;
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class OrderItem {
private double unitPrice;
private String orderItemInventoryStatus;
private String zipCode;
private double quantity;
private String shipModeCode;
private String shipModeId;
private String shippingCharge;
private String orderItemId;
private String currency;
private double orderItemPrice;
private String correlationGroup;
private String partNumber;
private boolean freeGift;
@JsonProperty("xitem_isPersonalAddressesAllowedForShipping")
private boolean isPersonalAddressesAllowedForShipping;
private boolean bundleItem;
private BundleInfo bundleInfo;
private String productId;
private String offerID;
private ProductDetails productDetails = new ProductDetails();
private JsonNode availableShippingMethods;
private double totalAdjustment;
private JsonNode adjustment;
private String addressId;
private String firstName;
private String lastName;
private List<String> addressLine;
private String city;
private String state;
private String postalCode;
private String stateOrProvinceName;
private String country;
private String phoneNumber;
private String companyName;
private List<OrderItemExtendAttribute> orderItemExtendAttribute;
private List<String> itemsIdsInBundle = new ArrayList<>();
private String itemShippingType;
private String isAssemblyRequired;
private String officeAddress;
public AddressVo getShippingAddress() {
if(addressId!=null && addressLine!=null && addressLine.get(0)!=null && zipCode!=null && !addressLine.get(0).isEmpty() && !zipCode.isEmpty() && !addressId.isEmpty()) {
String addressLineStr = addressLine.get(0);
if(addressLine.size() > 1 && addressLine.get(1)!=null) {
addressLineStr = addressLine.get(0) +" , " + addressLine.get(1);
}
return new AddressVo(addressId, firstName, lastName, addressLineStr, null, zipCode, city, state, country, phoneNumber, companyName, null,officeAddress);
}else {
return null;
}
}
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class BundleInfo{
String catEntryId;
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ProductDetails{
JsonNode inventory;
@JsonProperty("product-info")
ProductInfo productinfo= new ProductInfo();
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ProductInfo{
@JsonProperty("productinfo")
ProductInfoInner productinfoinner;
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ProductInfoInnerListWrapper {
List<ProductInfoInner> productinfo;
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ProductInfoInner{
String id;
String name;
String shortDescription;
String longDescription;
String imageAltDescription;
String sellable;
String fullImage;
String thumbnail;
String manufacturer;
String categoryName;
String parentCatalogEntryID;
String parentSkuId;
boolean sofItem;
List<String> adBug;
List<ProductAttributes> productAttributes;
private static final String PRODUCT_ATTRIBUTE = "Defining";
private static final String SPECIALORDER = "SPECIALORDER";
public void filterProductAttributes() {
Optional.ofNullable(this.getProductAttributes()).ifPresent(atts -> {
if (atts.stream()
.anyMatch(att -> SPECIALORDER.equalsIgnoreCase(att.getName()) && att.getValues() != null
&& att.getValues().get(0) != null
&& "Y".equalsIgnoreCase(att.getValues().get(0).getValue()))) {
this.setSofItem(true);
}
List<ProductAttributes> filteredAttributes = atts.stream()
.filter(att -> PRODUCT_ATTRIBUTE.equalsIgnoreCase(att.getUsage())).collect(Collectors.toList());
this.setProductAttributes(filteredAttributes);
});
}
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ProductAttributes{
String name;
String usage;
List<Values> values;
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Values{
String value;
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class OrderExtendAttribute{
String attributeName;
String attributeValue;
}
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public static class OrderItemExtendAttribute{
String attributeName;
String attributeValue;
String attributeType;
}
}
//依赖类
package com.pr;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class AddressVo {
String id;
String firstName;
String lastName;
String address;
String aptName;
String zipCode;
String city;
String state;
String country;
String phoneNumber;
String companyName;
String emailId;
String officeAddress;
}
//驱动程序类包com.pr;
import java.io.File;
import java.io.IOException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Driver {
public static void main(String[] args) {
String json = ""; //given above
ObjectMapper objectMapper = new ObjectMapper();
//objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
try {
ConfirmedOrderResponseVo orderResponseVo = objectMapper.readValue(json, ConfirmedOrderResponseVo.class);
} catch (IOException e) {
e.printStackTrace();
}
}
}
暂无答案!
目前还没有任何答案,快来回答吧!