bizContent is a json String, I want to parse it to an QueryOrderInfo object
public static void main(String[] args) {
BaseResponse queryOrderInfoBaseResponse = null;
try {
queryOrderInfoBaseResponse = new ObjectMapper().readValue("{\"returnCode\":\"SUCCESS\",\"biz_content\":\"{\\\"mchReserved\\\":\\\"1\\\",\\\"cmbOrderId\\\":\\\"900119022715203210134445\\\",\\\"dscAmt\\\":\\\"0\\\",\\\"payType\\\":\\\"ZF\\\",\\\"orderId\\\":\\\"9001004180329103417277\\\",\\\"txnTime\\\":\\\"20190227152032\\\",\\\"merId\\\":\\\"3089991701207X7\\\",\\\"currencyCode\\\":\\\"156\\\",\\\"txnAmt\\\":\\\"1\\\",\\\"tradeState\\\":\\\"S\\\"}\",\"sign\":\"kGE7mwX/ubRlPsPZGNydjY3uCjILgGuxD4j1e/inyC/DlHn5o7LkISpmrH0YQvoZT6lyOxtr9uIkKnqVcTMZNYeYIBU+Tz8NRaPZHuFr/qQb0+fUgEgq5j9ovaFczAF8wrnEfIRYBEqp0ERtK7NG+X6eZLIr9nNVy31eKcnFx1tToJ/zPYN91GOKOtTrJaJrKeDY4+r3ctzsDhnD+TO2MX5zfvW0WLoUjvX5geiYLVpt022BiyxSJyOsrDS858RBmZ5FbVlYP0v/WqwX+J8VY1kDSLxvPtSZuPnsluJPXw6ccnYNH8dir0VgrYfrWRvnupctIm2elCmL7ES6KzDTGg==\",\"encoding\":\"UTF-8\",\"version\":\"0.0.1\",\"signMethod\":\"01\",\"respCode\":\"SUCCESS\"}", new TypeReference() {
});
QueryOrderInfo queryOrderInfo = queryOrderInfoBaseResponse.fromJson();
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
BaseResponse class
@NoArgsConstructor
@Data
public class BaseResponse {
private String returnCode;
@JsonProperty(value = "biz_content")
private String bizContent;
private String sign;
private String encoding;
private String version;
private String signMethod;
private String respCode;
private String errCode;
private String respMsg;
private T data;
public T fromJson() {
try {
return new ObjectMapper().readValue(this.bizContent, new TypeReference() {
});
} catch (JsonProcessingException e) {
return null;
}
}
}
0 comments:
Post a Comment
Thanks