使用ToString方法直接打印值并按如下方式构造类
ObjectMapper mapper = new ObjectMapper();
Data data = mapper.readValue(string, Data.class);
System.out.println(data);
数据类
public class Data {
@JsonProperty("TransferRecord")
private TransferRecord transferRecord;
@JsonProperty("ResultCode")
private int
resultCode;
@JsonProperty("ErrorCodes")
private List<ErrorCode> errorCodes;
@Override
public String toString() {
return "Data [transferRecord=" + transferRecord + ", resultCode=" + resultCode + ", errorCodes=" + errorCodes
+ "]";
}
}
错误代码类:
public class ErrorCode {
@JsonProperty("Code")
private String code;
@JsonProperty("Context")
private String context;
@Override
public String toString() {
return "ErrorCode [code=" + code + ", context=" + context + "]";
}
}
TransferRecord类:
public class TransferRecord {
@JsonProperty("TransferId")
private TransferId transferId;
@JsonProperty("SkuCode")
private String skuCode;
@JsonProperty("Price")
private Price price;
@JsonProperty("CommissionApplied")
private BigDecimal commissionApplied;
@JsonProperty("StartedUtc")
private Date startedUtc;
@JsonProperty("CompletedUtc")
private Date completedUtc;
@JsonProperty("ProcessingState")
private String processingState;
@JsonProperty("ReceiptText")
private String receiptText;
@JsonProperty("ReceiptParams")
private Map<String, String> receiptParams;
@JsonProperty("AccountNumber")
private String accountNumber;
@Override
public String toString() {
return "TransferRecord [transferId=" + transferId + ", skuCode=" + skuCode + ", price=" + price
+ ", commissionApplied=" + commissionApplied + ", startedUtc=" + startedUtc + ", completedUtc="
+ completedUtc + ", processingState=" + processingState + ", receiptText=" + receiptText
+ ", receiptParams=" + receiptParams + ", accountNumber=" + accountNumber + "]";
}
}
TransferID类:
public class TransferId {
@JsonProperty("TransferRef")
private String transferRef;
@JsonProperty("DistributorRef")
private String distributorRef;
@Override
public String toString() {
return "TransferId [transferRef=" + transferRef + ", distributorRef=" + distributorRef + "]";
}
}
价格等级:
public class Price {
@JsonProperty("CustomerFee")
private int customerFee;
@JsonProperty("DistributorFee")
private int distributorFee;
@JsonProperty("ReceiveValue")
private int receiveValue;
@JsonProperty("ReceiveCurrencyIso")
private String receiveCurrencyIso;
@JsonProperty("ReceiveValueExcludingTax")
private int receiveValueExcludingTax;
@JsonProperty("TaxRate")
private int taxRate;
@JsonProperty("TaxName")
private String taxName;
@JsonProperty("TaxCalculation")
private String taxCalculation;
@JsonProperty("SendValue")
private int sendValue;
@JsonProperty("SendCurrencyIso")
private String sendCurrencyIso;
@Override
public String toString() {
return "Price [customerFee=" + customerFee + ", distributorFee=" + distributorFee + ", receiveValue="
+ receiveValue + ", receiveCurrencyIso=" + receiveCurrencyIso + ", receiveValueExcludingTax="
+ receiveValueExcludingTax + ", taxRate=" + taxRate + ", taxName=" + taxName + ", taxCalculation="
+ taxCalculation + ", sendValue=" + sendValue + ", sendCurrencyIso=" + sendCurrencyIso + "]";
}
}