Helius
2022-03-10 70ccc6d4225d2cb85244d5e2dca3949f6677707c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
 
    }
}