Lambda
-
技术点
- Map键值对取值, key是在"|"转义, value是在::取值
-
实体类
package com.jd.saas.rd.data.proxy.api.domain.huijin.request;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @Author xxx
* @Date 2021-03-15 15:07
* @Description: 汇金-商品信息变更
**/
@Data
public class ShopInfoNoticeReq implements Serializable {
/**
* serialVersionUID
*/
private static final long serialVersionUID = -9064068204587469116L;
/**
* itemBase 商品主档,
* stock 库存,
* item 门店商品,
* price 价格,
* category 分类,
* store_category 门店个性分类,
* shop 店铺的更新,
*/
private String type;
private List<ShopInfoNoticeItem> idList;
private String v;
private String format;
private String sign;
private String timestamp;
}
- 测试类
package com.jd.saas.rd.data.proxy.web;
import com.alibaba.fastjson.JSON;
import com.jd.saas.rd.data.proxy.api.domain.huijin.request.ShopInfoNoticeItem;
import com.jd.saas.rd.data.proxy.api.domain.huijin.request.ShopInfoNoticeReq;
import java.util.Map;
import java.util.stream.Collectors;
public class Test02 {
public static void main(String[] args) {
String str = "{"v": "v3","format": "json","sign": "e70a8e2a359544afa942e6918b6bdle6","idList": [{"ids": "6914973606753|1108375","storeCode": "1101"}],"type": "price","timestamp": 1616574994683}";
ShopInfoNoticeReq parseObject = JSON.parseObject(str, ShopInfoNoticeReq.class);
Map<String, String> storeMap = parseObject.getIdList().stream().collect(Collectors.toMap(shopInfoNoticeItem -> {
String[] res = shopInfoNoticeItem.getIds().split("\|");
return res[1];
}, ShopInfoNoticeItem::getStoreCode));
storeMap.forEach((k, v) -> System.out.println("{key=" + k + ", value=" + v + "}"));
//TODO 输出:{key=1108375, value=1101}
}
}