- 测试代码
String goodsPrice = "{"appid":"1637474419867659","code":0,"msg":"","qid":"c167447f-78da-4db4-b886-623fecc45335"," +
""result":true,"resultList":[{"region_code":"5010","barcode":"40"}],"sign":"22ACBF590295DC4D05017F69D382ADD6"," +
""timestamp":1620371185,"version":"2.3"}";
BaseResponse<StorePriceQueryResp> goods = JSON.parseObject(goodsPrice, new TypeReference<BaseResponse<StorePriceQueryResp>>() {
});
System.out.println(JSON.toJSON(goods));
//TODO: {"msg":"","result":true,"resultList":[{"barcode":"40","region_code":"5010"}]}
- 泛型类
@Data
public class BaseResponse<T> {
private String msg;
private Boolean result;
private List<T> resultList;
private Integer total;
}
- 实体类
@Data
public class StorePriceQueryResp {
/**
* ERP门店编码
*/
private String region_code;
/**
* 商品条码
*/
private String barcode;
/**
* ERP商品编码
*/
private String item_code;
/**
* 牵牛花内码
*/
private Long rid;
/**
* 当前售价
*/
private String sale_price;
/**
* 市场价
*/
private String reference_price;
/**
* 最近修改时间
*/
private String timestamp;
}
- 原数据
{
"appid": "1637474419867659",
"code": 0,
"msg": "",
"qid": "c167447f-78da-4db4-b886-623fecc45335",
"result": true,
"resultList": [
{
"region_code": "5010",
"barcode": "40"
}
],
"sign": "22ACBF590295DC4D05017F69D382ADD6",
"timestamp": 1620371185,
"version": "2.3"
}
- 转换后数据
{
"msg": "",
"result": true,
"resultList": [
{
"barcode": "40",
"region_code": "5010"
}
]
}