package com.matrix.component.tools;
|
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
|
import java.util.Objects;
|
import java.util.Set;
|
|
public class JSONUtil {
|
|
/**
|
* 用第二个json对象覆盖第一个json对象的值,并返回一个新的json对象
|
*
|
* @param source
|
* @param target
|
* @return
|
*/
|
public static JSONObject extend(JSONObject source, JSONObject target) {
|
|
Objects.requireNonNull(source);
|
Objects.requireNonNull(target);
|
JSONObject jsonObject = JSON.parseObject(source.toJSONString());
|
|
Set<String> set = target.keySet();
|
|
set.stream().forEach(key -> {
|
jsonObject.put(key, target.get(key));
|
|
});
|
|
return jsonObject;
|
|
}
|
}
|