代码:
public static void main(String[] args) {
String s1 = "[\n" +
" \\n\" + \"{\n" +
" \\n\" + \"\\\"availablePrice\\\": 100,\n" +
" \\n\" + \"\\\"highestPrice\\\": 100,\n" +
" \\n\" + \"\\\"individualLimitNum\\\": -1,\n" +
" \\n\" + \"\\\"isAreaSale\\\": 1,\n" +
" \\n\" + \"\\\"isForcast\\\": 0,\n" +
" \\n\" + \"\\\"isPresell\\\": 0,\n" +
" \\n\" + \"\\\"isSeckill\\\": 0,\n" +
" \\n\" + \"\\\"lackOfStock\\\": 0,\n" +
" \\n\" + \"\\\"managementState\\\": 1,\n" +
" \\n\" + \"\\\"marketPrice\\\": 1,\n" +
" \\n\" + \"\\\"memberPrice\\\": 100,\n" +
" \\n\" + \"\\\"mpId\\\": 1002104700000050,\n" +
" \\n\" + \"\\\"nowDate\\\": 1565084653994,\n" +
" \\n\" + \"\\\"preferentialPrice\\\": 0,\n" +
" \\n\" + \"\\\"price\\\": 100,\n" +
" \\n\" + \"\\\"promotionIcon\\\": [\n" +
" \\n\" + \"{\n" +
" \\n\" + \"\\\"bgColor\\\": \\\"f23030\\\",\n" +
" \\n\" + \"\\\"fontColor\\\": \\\"ffffff\\\",\n" +
" \\n\" + \"\\\"iconText\\\": \\\"换购\\\",\n" +
" \\n\" + \"\\\"iconUrl\\\": \\\"http: //cdn.oudianyun.com/lyf/branch/back-promotion/1481619801795_4770_102.png\\\",\n" +
" \\n\" + \"\\\"weight\\\": 1\\n\" + \"\n" +
" }\\n\" + \"\n" +
" ],\n" +
" \\n\" + \"\\\"promotionIconTexts\\\": [\n" +
" \\n\" + \"\\\"换购\\\"\\n\" + \"\n" +
" ],\n" +
" \\n\" + \"\\\"promotionIconUrls\\\": [\n" +
" \\n\" + \"\\\"http: //cdn.oudianyun.com/lyf/branch/back-promotion/1481619801795_4770_102.png\\\"\\n\" + \"\n" +
" ],\n" +
" \\n\" + \"\\\"promotionPrice\\\": 100,\n" +
" \\n\" + \"\\\"stockNum\\\": 0,\n" +
" \\n\" + \"\\\"stockText\\\": \\\"0\\\",\n" +
" \\n\" + \"\\\"tax\\\": 0,\n" +
" \\n\" + \"\\\"totalLimitNum\\\": -1,\n" +
" \\n\" + \"\\\"valid\\\": false\\n\" + \"\n" +
" },\n" +
" \\n\" + \"{\n" +
" \\n\" + \"\\\"availablePrice\\\": 10,\n" +
" \\n\" + \"\\\"highestPrice\\\": 10,\n" +
" \\n\" + \"\\\"individualLimitNum\\\": -1,\n" +
" \\n\" + \"\\\"isAreaSale\\\": 1,\n" +
" \\n\" + \"\\\"isForcast\\\": 0,\n" +
" \\n\" + \"\\\"isPresell\\\": 0,\n" +
" \\n\" + \"\\\"isSeckill\\\": 0,\n" +
" \\n\" + \"\\\"lackOfStock\\\": 0,\n" +
" \\n\" + \"\\\"managementState\\\": 1,\n" +
" \\n\" + \"\\\"marketPrice\\\": 10,\n" +
" \\n\" + \"\\\"memberPrice\\\": 10,\n" +
" \\n\" + \"\\\"mpId\\\": 1002104800000108,\n" +
" \\n\" + \"\\\"nowDate\\\": 1565084653995,\n" +
" \\n\" + \"\\\"preferentialPrice\\\": 0,\n" +
" \\n\" + \"\\\"price\\\": 10,\n" +
" \\n\" + \"\\\"promotionIcon\\\": [\n" +
" \\n\" + \"{\n" +
" \\n\" + \"\\\"bgColor\\\": \\\"f23030\\\",\n" +
" \\n\" + \"\\\"fontColor\\\": \\\"ffffff\\\",\n" +
" \\n\" + \"\\\"iconText\\\": \\\"换购\\\",\n" +
" \\n\" + \"\\\"iconUrl\\\": \\\"http: //cdn.oudianyun.com/lyf/branch/back-promotion/1481619801795_4770_102.png\\\",\n" +
" \\n\" + \"\\\"weight\\\": 1\\n\" + \"\n" +
" }\\n\" + \"\n" +
" ],\n" +
" \\n\" + \"\\\"promotionIconTexts\\\": [\n" +
" \\n\" + \"\\\"换购\\\"\\n\" + \"\n" +
" ],\n" +
" \\n\" + \"\\\"promotionIconUrls\\\": [\n" +
" \\n\" + \"\\\"http: //cdn.oudianyun.com/lyf/branch/back-promotion/1481619801795_4770_102.png\\\"\\n\" + \"\n" +
" ],\n" +
" \\n\" + \"\\\"promotionPrice\\\": 10,\n" +
" \\n\" + \"\\\"stockNum\\\": 0,\n" +
" \\n\" + \"\\\"stockText\\\": \\\"0\\\",\n" +
" \\n\" + \"\\\"tax\\\": 0,\n" +
" \\n\" + \"\\\"totalLimitNum\\\": -1,\n" +
" \\n\" + \"\\\"valid\\\": false\\n\" + \"\n" +
" }\\n\" + \"\n" +
"]";
List<ProductBaseVO> vos = JSONObject.parseArray(s1, ProductBaseVO.class);
Gson gson = new Gson();
for (ProductBaseVO vo : vos) {
ProductPriceStockVO stockVO = new ProductPriceStockVO();
BeanMapper.copy(vo, stockVO);
System.out.println(JSON.toJSONString(stockVO));
System.out.println(gson.toJson(stockVO));
}
}
与Gson对比输出:
{"availablePrice":100,"highestPrice":100,"individualLimitNum":-1,"isPresell":0,"isSeckill":0,"lackOfStock":1,"managementState":1,"marketPrice":1,"memberPrice":100,"mpId":1002104700000050,"preferentialPrice":0,"price":100,"promotionIcon":[],"promotionIconTexts":[],"promotionIconUrls":[],"promotionPrice":100,"stockNum":0,"stockText":"0","tax":0,"totalLimitNum":-1} {"mpId":1002104700000050,"price":100,"marketPrice":1,"tax":0,"stockNum":0,"stockText":"0","lackOfStock":1,"promotionPrice":100,"preferentialPrice":0,"promotionIcon":[{"iconText":"换购","iconUrl":"http://cdn.oudianyun.com/lyf/branch/back-promotion/1481619801795_4770_102.png","bgColor":"f23030","fontColor":"ffffff","weight":1}],"promotionIconUrls":["http://cdn.oudianyun.com/lyf/branch/back-promotion/1481619801795_4770_102.png"],"promotionIconTexts":["换购"],"isSeckill":0,"memberPrice":100,"managementState":1,"isPresell":0,"highestPrice":100} {"availablePrice":10,"highestPrice":10,"individualLimitNum":-1,"isPresell":0,"isSeckill":0,"lackOfStock":1,"managementState":1,"marketPrice":10,"memberPrice":10,"mpId":1002104800000108,"preferentialPrice":0,"price":10,"promotionIcon":[],"promotionIconTexts":[],"promotionIconUrls":[],"promotionPrice":10,"stockNum":0,"stockText":"0","tax":0,"totalLimitNum":-1} {"mpId":1002104800000108,"price":10,"marketPrice":10,"tax":0,"stockNum":0,"stockText":"0","lackOfStock":1,"promotionPrice":10,"preferentialPrice":0,"promotionIcon":[{"iconText":"换购","iconUrl":"http://cdn.oudianyun.com/lyf/branch/back-promotion/1481619801795_4770_102.png","bgColor":"f23030","fontColor":"ffffff","weight":1}],"promotionIconUrls":["http://cdn.oudianyun.com/lyf/branch/back-promotion/1481619801795_4770_102.png"],"promotionIconTexts":["换购"],"isSeckill":0,"memberPrice":10,"managementState":1,"isPresell":0,"highestPrice":10}