package com.xrxs.api.data.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xrxs.api.data.exception.DataFilterParseException;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
/**
* 使用的是递归的方式来处理 key, key 的书写形式类似于:
*
* user.fields.备注 # {"user": {"fields":{"备注": "这是备注"}}}
* user.personList.[2].name # {"user": {"personList": [{}, {}, {"name": "value"}]}}
* user.personList.[].name # {"user": {"personList": [{"name": "value"}, {}, {}]}} 对此list里所有元素处理
* [].user.personList.[].name # [{"user": {"personList": [{"name": "value"}, {}]}}, {"user": {"personList": [{}, {}]}}]
* personList.[2].name # {"personList": [{}, {}, {}]}
*
* 如果不是一一对应的值, 比如下面这样, 就会抛错
* [].[].name # [[{"name": "value"}, {}], {{}, {}}, [[], []]]
* 正确例子是, 指明是数组里的第一个元素:
* [0].[].name # [[{"name": "value"}, {}], {{}, {}}, [[], []]]
*
* 主要提供这三种功能;
* 1- 设置json对象值: 对 key 对应的值, 执行 function 方法;
* 2- include 白名单模式, 将值收集, 然后转换成新的对象, 但是不改变原有的结构;
* 3- 将值收集成新的对象, 新的对象结构可以改变;
* -
* toJsonString = 不会隐藏掉为null的字段
*
* @ClassName JsonUtils
* @Description 根据key能操作 JSONObject
* @Author kezhan
* @Date 2021/1/6 10:45 下午
*/
public class JsonUtil {
private static final String KEY_SEPARATOR = ".";
private static final String ARRAY_PREFIX = "[";
private static final String ARRAY_SUFFIX = "]";
private static final String ERROR_NO_KEY = "没有 key: '%s', key 的规则错误";
private static final String ERROR_OUT_DEEPIN = "key的层级: '%s' 的规则与对象的映射有误!";
private static final String ERROR_OUT_ARRAY_INDEX = "key 规则错误, 输入索引 '%s' 大于数组下标";
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
static {
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
/**
* 1- 设置json对象值: 对 key 对应的值, 执行 function 方法;<p>
* 如果 key 不包含 [], 则 function 只会执行一次; 否则则是对所有符合 key 规则的值, 都执行一次 function
*
* @param jsonObjArr object 源对象, 对象会被修改, jsonObject or jsonArray
* @param key key 要符合约定好的规则, 不然就会抛出解析错误的 error
* key 按照 '.' 来区分层次, 并且每次递归, 都是只是往后面深一层, 而 object 是 key 前一层的对象;
* @param function value 的自定义修改规则
* @return 修改后的值
*/
public static Object setObjectValue(Object jsonObjArr, String key, Function<Object, Object> function) {
// 出口
if (isBlack(key)) {
return function.apply(jsonObjArr);
}
String[] wrapper = splitKey(key);
if (jsonObjArr instanceof JSONObject) {
JSONObject jsonObject = ((JSONObject) jsonObjArr);
Object oldObjectValue = jsonObject.get(wrapper[0]);
if (oldObjectValue == null) {
throw new DataFilterParseException(ERROR_NO_KEY, wrapper[0]);
}
jsonObject.put(wrapper[0], setObjectValue(oldObjectValue, wrapper[1], function));
} else if (jsonObjArr instanceof JSONArray) {
JSONArray jsonArray = ((JSONArray) jsonObjArr);
Integer arrayIndex = parseArrayKey(wrapper[0]);
if (arrayIndex == null) {
for (int i = 0, jsonArraySize = jsonArray.size(); i < jsonArraySize; i++) {
jsonArray.set(i, setObjectValue(jsonArray.get(i), wrapper[1], function));
}
} else {
jsonArray.set(arrayIndex, setObjectValue(jsonArray.get(arrayIndex), wrapper[1], function));
}
} else {
// 层级超出来了;
throw new DataFilterParseException(ERROR_OUT_DEEPIN, key);
}
return jsonObjArr;
}
/**
* 黑名单模式, 将对应的 key 直接 remove 掉
*
* key -> !key.contains(".") 的意思是, 当 user.fields.school 递归到 fields 对象时,
* 也就是 key 为 school, (为 fields 里的 key)
*/
public static Object removeObjectValue(Object jsonObjArr, String key) {
return handlerObjectValue(jsonObjArr, key,
subKey -> !subKey.contains("."),
(subJsonObjArr, subKey) -> {
if (subJsonObjArr instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) subJsonObjArr;
if (!jsonObject.containsKey(subKey)) {
throw new DataFilterParseException(ERROR_NO_KEY, subKey);
}
jsonObject.remove(subKey);
} else if (subJsonObjArr instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) subJsonObjArr;
Integer index = JsonUtil.parseArrayKey(subKey);
if (index == null) {
jsonArray.clear();
} else {
try {
jsonArray.remove((int) index);
} catch (IndexOutOfBoundsException exception) {
throw new DataFilterParseException(ERROR_OUT_ARRAY_INDEX, index);
}
}
}
return subJsonObjArr;
});
}
/**
* 对 key 所有能满足 predicate 的值, 执行 function 方法;<p>
* key 按照 '.' 来区分层次, 并且每次递归, 都是只是往后面深一层, 而 object 是 key 前一层的对象;
*
* ps: 只修改了 setObjectValue 方法中出口的实现, 其他并未改变;
*
* @param jsonObjArr object 源对象, 对象会被修改, jsonObject or jsonArray
* @param key key 要符合约定好的规则, 不然就会抛出解析错误的 error
* @param predicate 递归出口的条件
* @param function value 的自定义修改规则, 源对象 jsonObjArr, key 值, 返回对象 jsonObjArr
* @return 修改后的值
*/
public static Object handlerObjectValue(Object jsonObjArr, String key,
Predicate<String> predicate,
BiFunction<Object, String, Object> function) {
// 出口
if (predicate.test(key)) {
return function.apply(jsonObjArr, key);
}
String[] wrapper = splitKey(key);
if (jsonObjArr instanceof JSONObject) {
JSONObject jsonObject = ((JSONObject) jsonObjArr);
Object oldObjectValue = jsonObject.get(wrapper[0]);
if (oldObjectValue == null) {
throw new DataFilterParseException(ERROR_NO_KEY, wrapper[0]);
}
jsonObject.put(wrapper[0], handlerObjectValue(oldObjectValue, wrapper[1], predicate, function));
} else if (jsonObjArr instanceof JSONArray) {
JSONArray jsonArray = ((JSONArray) jsonObjArr);
Integer arrayIndex = parseArrayKey(wrapper[0]);
if (arrayIndex == null) {
for (int i = 0, jsonArraySize = jsonArray.size(); i < jsonArraySize; i++) {
jsonArray.set(i, handlerObjectValue(jsonArray.get(i), wrapper[1], predicate, function));
}
} else {
jsonArray.set(arrayIndex, handlerObjectValue(jsonArray.get(arrayIndex), wrapper[1], predicate, function));
}
} else {
// 层级超出来了;
throw new DataFilterParseException(ERROR_OUT_DEEPIN, key);
}
return jsonObjArr;
}
/**
* 根据 key 获取值, 如果 key 中包含 [], 则会返回 JsonArray 对象,
*
* @param jsonObjArr 源对象, 不会被修改, 不能为 null
* @param key key
* @return value. 返回的值是 jsonObjArr 的引用
*/
public static Object getObjectValue(Object jsonObjArr, String key) {
// 出口
if (isBlack(key)) {
return jsonObjArr;
}
String[] wrapper = splitKey(key);
if (jsonObjArr instanceof JSONObject) {
JSONObject jsonObject = ((JSONObject) jsonObjArr);
Object oldObjectValue = jsonObject.get(wrapper[0]);
if (oldObjectValue == null) {
throw new DataFilterParseException(ERROR_NO_KEY, wrapper[0]);
}
return getObjectValue(oldObjectValue, wrapper[1]);
} else if (jsonObjArr instanceof JSONArray) {
JSONArray jsonArray = ((JSONArray) jsonObjArr);
Integer arrayIndex = parseArrayKey(wrapper[0]);
if (arrayIndex == null) {
JSONArray array = new JSONArray();
for (int i = 0, jsonArraySize = jsonArray.size(); i < jsonArraySize; i++) {
array.add(i, getObjectValue(jsonArray.get(i), wrapper[1]));
}
return array;
} else {
return getObjectValue(jsonArray.get(arrayIndex), wrapper[1]);
}
} else {
// 层级超出来了;
throw new DataFilterParseException(ERROR_OUT_DEEPIN, key);
}
}
// ------------------------------ end 1
/**
* 2- <p>include 白名单模式, 将值收集, 然后转换成新的对象, 不改变原有的对象结构;</p>
* 数组类型的字段值收集时, 下标需要是一一对应的,
* 如果是 [], 新对象为空 ((JSONArray) newJsonObjArr).size() == 0, 则是将旧对象里对应的值一个个添加到新对象,
* 而如果新对象不是空, 则是根据数组下标, 将 newJsonObjArr 里对应的下标的对象的值一一对应修改;
* 如果指明了下标 [2], 则是会去修改 ((JSONArray) newJsonObjArr).get(2) 的对象, 注意控制坐标.
*
* @param oldJsonObjArr object 源对象, 对象不会被修改
* @param key key 要符合约定好的规则, 不然就会抛出解析错误的 error
* @param newJsonObjArr 新的对象, 可以为 null,
* @param function value 的自定义修改规则
* @return 修改后的 newJsonObjArr
*/
public static Object putValueInNewObject(Object oldJsonObjArr, String key, Object newJsonObjArr,
Function<Object, Object> function) {
// 出口
if (isBlack(key)) {
return function.apply(oldJsonObjArr);
}
String[] wrapper = splitKey(key);
if (oldJsonObjArr instanceof JSONObject) {
if (newJsonObjArr == null) {
newJsonObjArr = new JSONObject();
}
JSONObject oldJsonObject = ((JSONObject) oldJsonObjArr);
JSONObject newJsonObject = ((JSONObject) newJsonObjArr);
Object oldObjectValue = oldJsonObject.get(wrapper[0]);
if (oldObjectValue == null) {
throw new DataFilterParseException(ERROR_NO_KEY, wrapper[0]);
}
Object object = putValueInNewObject(oldObjectValue, wrapper[1], newJsonObject.get(wrapper[0]), function);
newJsonObject.put(wrapper[0], object);
} else if (oldJsonObjArr instanceof JSONArray) {
if (newJsonObjArr == null) {
newJsonObjArr = new JSONArray();
}
JSONArray oldJsonArray = ((JSONArray) oldJsonObjArr);
JSONArray newJsonArray = ((JSONArray) newJsonObjArr);
Integer arrayIndex = parseArrayKey(wrapper[0]);
// []
if (arrayIndex == null) {
// newJsonObjArr.size() == 0, 则是追加, 否则则是处理和添加对应的值;
if (newJsonArray.size() == 0) {
for (Object oldObjectValue : oldJsonArray) {
newJsonArray.add(putValueInNewObject(oldObjectValue, wrapper[1], null, function));
}
} else {
for (int i = 0; i < oldJsonArray.size(); i++) {
Object oldObjectValue = oldJsonArray.get(i);
Object element = putValueInNewObject(oldObjectValue, wrapper[1], newJsonArray.get(i), function);
newJsonArray.set(i, element);
}
}
} else {
Object oldObjectValue = oldJsonArray.get(arrayIndex);
Object element = putValueInNewObject(oldObjectValue, wrapper[1], newJsonArray.get(arrayIndex), function);
newJsonArray.set(arrayIndex, element);
}
} else {
// 层级超出来了;
throw new DataFilterParseException(ERROR_OUT_DEEPIN, key);
}
return newJsonObjArr;
}
// ------------------------------ end 2
/**
* 3- 将值收集成新的对象, 新的对象结构可以改变; [] 默认识别为 [0];
*
* @param oldObject 源对象, 不能为 null, 不会被修改
* @param oldKey 对应源对象的 key, 不能含有[], [] 会解析为 [0]
* @param newObject 新的对象, 可以为null
* @param newKey 对应新对象的 key,
* @param function value 的处理函数
*/
public static Object putValueInNewObjectByNewKey(Object oldObject, String oldKey,
Object newObject, String newKey,
Function<Object, Object> function) {
Object objectValue = getObjectValue(oldObject, oldKey);
Object apply = function.apply(objectValue);
return setJsonValueByKey(newObject, newKey, apply);
}
/**
* 根据一个 key 设置一个值;
*
* @param jsonObjArr 可以为 null; 如果为 null 就创建一个和 key 对应的 json 对象,
* @param key [] 时, size == 0, 则忽略, [2] 对对应下标进行处理;
* @return 修改后的 jsonObjArr 对象;
*/
public static Object setJsonValueByKey(Object jsonObjArr, String key, Object value) {
if (isBlack(key)) {
return value;
}
String[] wrapper = splitKey(key);
if (isArrayKey(wrapper[0])) {
if (jsonObjArr == null) {
jsonObjArr = new JSONArray();
}
JSONArray jsonArray = ((JSONArray) jsonObjArr);
Integer arrayIndex = parseArrayKey(wrapper[0]);
// []
if (arrayIndex == null) {
if (jsonArray.size() != 0) {
for (int i = 0; i < jsonArray.size(); i++) {
jsonArray.set(i, setJsonValueByKey(jsonArray.get(i), wrapper[1], value));
}
}
} else {
jsonArray.set(arrayIndex, setJsonValueByKey(jsonArray.get(arrayIndex), wrapper[1], value));
}
} else {
if (jsonObjArr == null) {
jsonObjArr = new JSONObject();
}
JSONObject jsonObject = ((JSONObject) jsonObjArr);
Object result = setJsonValueByKey(jsonObject.get(wrapper[0]), wrapper[1], value);
jsonObject.put(wrapper[0], result);
}
return jsonObjArr;
}
// ------------------------------ end 3
// ------------------------------ other
/**
* 转为 json 时, 包含空字符串
*/
public static String toJsonString(Object obj) {
if (obj == null) {
return null;
}
if (obj.getClass() == String.class) {
return obj.toString();
}
String json;
try {
json = OBJECT_MAPPER.writeValueAsString(obj);
} catch (JsonProcessingException e) {
throw new DataFilterParseException(obj + "序列化失败", e);
}
return json;
}
/**
* 序列化 json string 时
*
* @return jsonObjArr
*/
public static Object toJson(Object sourceObject) {
String sourceString;
if (sourceObject instanceof String) {
sourceString = (String) sourceObject;
} else {
sourceString = toJsonString(sourceObject);
}
return JSON.parse(sourceString, Feature.OrderedField);
}
public static List<String> toListString(String content) {
return JSON.parseObject(content, new TypeReference<List<String>>() {
});
}
/**
* key 可能为: [], [1]
*
* @param key [1]
* @return [] -> null, [1] -> 1
*/
public static Integer parseArrayKey(String key) {
if (!isArrayKey(key)) {
throw new DataFilterParseException("'%s' 不是正确的数组 key 映射.", key);
}
String right = key.substring(1, key.length() - 1);
if (isBlack(right)) {
return null;
}
return Integer.parseInt(right);
}
private static boolean isArrayKey(String key) {
return key.startsWith(ARRAY_PREFIX) && key.endsWith(ARRAY_SUFFIX);
}
/**
* 将 user.fields.like 按照第一个 '.' 切割成两部分
* string[0] 不为null, string[1] 可能为 null
*
* @param key user.fields.like
* @return string[0]: user, string[1]: fields.like;
*/
private static String[] splitKey(String key) {
int i = key.indexOf(KEY_SEPARATOR);
if (i != -1) {
String left = key.substring(0, i);
String right = key.substring(i + 1);
return new String[]{left.trim(), right.trim()};
}
return new String[]{key.trim(), null};
}
private static boolean isBlack(String key) {
return key == null || key.trim().isEmpty();
}
}
package com.xrxs.api.data.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import cn.hutool.core.date.StopWatch;
import lombok.Data;
class JsonUtilTest {
private HashMap<String, Object> getStringObjectHashMap() {
HashMap<String, Object> fields = new HashMap<>();
fields.put("备注", "这是备注");
fields.put("爱好", "女");
fields.put("school", "清华");
HashMap<String, Object> user = new HashMap<>();
user.put("fields", fields);
user.put("age", 18);
user.put("name", "测试用户");
user.put("personList", Arrays.asList(new HashMap<>(user), new HashMap<>(user)));
HashMap<String, Object> obj = new HashMap<>();
obj.put("user", user);
return obj;
}
private List<HashMap<String, Object>> getArray() {
HashMap<String, Object> fields = new HashMap<>();
fields.put("备注", "这是备注");
fields.put("爱好", "女");
fields.put("school", "清华");
HashMap<String, Object> user = new HashMap<>();
user.put("fields", fields);
user.put("age", 18);
user.put("name", "测试用户");
return Arrays.asList(new HashMap<>(user), new HashMap<>(user));
}
private List<List<HashMap<String, Object>>> getArrayArray() {
HashMap<String, Object> fields = new HashMap<>();
fields.put("备注", "这是备注");
fields.put("爱好", "女");
fields.put("school", "清华");
HashMap<String, Object> user = new HashMap<>();
user.put("fields", fields);
user.put("age", 18);
user.put("name", "测试用户");
List<HashMap<String, Object>> list = Arrays.asList(new HashMap<>(user), new HashMap<>(user));
return Arrays.asList(new ArrayList<>(list), new ArrayList<>(list));
}
@Test
void setNullObjectValue() throws JsonProcessingException {
HashMap<String, Object> obj = getStringObjectHashMap();
String s = JsonUtil.toJsonString(obj);
StopWatch watch = new StopWatch();
JSON.toJSON(s);
watch.start("1");
Object json = JSON.toJSON(s);
Object json1 = JSON.toJSON(s);
Object json2 = JSON.toJSON(s);
Object json3 = JSON.toJSON(s);
Object json4 = JSON.toJSON(s);
watch.stop();
ObjectMapper objectMapper = new ObjectMapper();
watch.start("2");
Object json11 = objectMapper.readTree(s);
Object json111 = objectMapper.readTree(s);
Object json112 = objectMapper.readTree(s);
Object json113 = objectMapper.readTree(s);
Object json114 = objectMapper.readTree(s);
watch.stop();
System.out.println(watch.prettyPrint());
}
@Test
void removeObjectValue2() {
HashMap<String, Object> obj = getStringObjectHashMap();
String s = JsonUtil.toJsonString(obj);
Object jsonObj = JsonUtil.toJson(s);
Object result = JsonUtil.removeObjectValue(jsonObj, "user.age");
result = JsonUtil.setObjectValue(result, "user.name", it -> null);
result = JsonUtil.removeObjectValue(result, "user.personList.[].fields.school");
System.out.println("result = " + JsonUtil.toJsonString(result));
}
@Test
void removeObjectValue3() {
List<HashMap<String, Object>> array = getArray();
Object jsonObj = JsonUtil.toJson(array);
Object result = JsonUtil.removeObjectValue(jsonObj, "[].age");
System.out.println("result = " + JsonUtil.toJsonString(result));
}
@Test
void removeObjectValue4() {
List<List<HashMap<String, Object>>> arrayArray = getArrayArray();
Object jsonObj = JsonUtil.toJson(arrayArray);
Object result = JsonUtil.removeObjectValue(jsonObj, "[].[].age");
result = JsonUtil.removeObjectValue(result, "[].[].fields.爱好");
System.out.println("result = " + JsonUtil.toJsonString(result));
}
@Test
void putValueInNewObject1() {
HashMap<String, Object> obj = getStringObjectHashMap();
Object json = JsonUtil.toJson(obj);
Object value = JsonUtil.putValueInNewObject(json, "user.age", null, Function.identity());
value = JsonUtil.putValueInNewObject(json, "user.name", value, Function.identity());
value = JsonUtil.putValueInNewObject(json, "user.fields.school", value, Function.identity());
value = JsonUtil.putValueInNewObject(json, "user.fields.爱好", value, Function.identity());
System.out.println("value = " + JsonUtil.toJsonString(value));
}
@Test
void putValueInNewObject2() {
List<HashMap<String, Object>> array = getArray();
Object json = JsonUtil.toJson(array);
Object value = JsonUtil.putValueInNewObject(json, "[1].age", null, Function.identity());
// value = JsonUtil.putValueInNewObject(json, "[].name", value, Function.identity());
// value = JsonUtil.putValueInNewObject(json, "[].fields.school", value, Function.identity());
// value = JsonUtil.putValueInNewObject(json, "[1].fields.爱好", value, Function.identity());
System.out.println("value = " + JsonUtil.toJsonString(value));
}
@Test
void putValueInNewObject3() {
List<List<HashMap<String, Object>>> arrayArray = getArrayArray();
Object json = JSON.toJSON(arrayArray);
Object value = JsonUtil.putValueInNewObject(json, "[].[].age", null, Function.identity());
value = JsonUtil.putValueInNewObject(json, "[].[].name", value, Function.identity());
value = JsonUtil.putValueInNewObject(json, "[1].[0].fields.school", value, Function.identity());
value = JsonUtil.putValueInNewObject(json, "[1].[1].fields.爱好", value, Function.identity());
System.out.println("value = " + JsonUtil.toJsonString(value));
}
@Test
void getObjectValue() {
{
HashMap<String, Object> map = getStringObjectHashMap();
Object json = JSON.toJSON(map);
Object value = JsonUtil.getObjectValue(json, "user.personList.[].fields");
System.out.println("value = " + JsonUtil.toJsonString(value));
}
{
List<List<HashMap<String, Object>>> arrayArray = getArrayArray();
Object json = JSON.toJSON(arrayArray);
Object value = JsonUtil.getObjectValue(json, "[].[].name");
System.out.println("value = " + JsonUtil.toJsonString(value));
}
}
@Test
void setJsonValueByKey() {
HashMap<String, Object> map = getStringObjectHashMap();
Object o1 = JsonUtil.toJson(map);
Object objectValue = JsonUtil.getObjectValue(o1, "user.personList");
Object o;
o = JsonUtil.setJsonValueByKey(null, "user.age", 18);
o = JsonUtil.setJsonValueByKey(o, "user.name", "测试用户");
o = JsonUtil.setJsonValueByKey(o, "user.fields.爱好", "女");
o = JsonUtil.setJsonValueByKey(o, "user.fields.备注", "备注");
o = JsonUtil.setJsonValueByKey(o, "user.fields.school", "清华");
o = JsonUtil.setJsonValueByKey(o, "user.personList", objectValue);
System.out.println("o = " + o);
}
@Test
void time() {
long epochSecond = Instant.now().getEpochSecond();
}
/**
* 序列化顺序的问题
*/
@Test
void nameOrdered() throws JsonProcessingException {
User user = new User();
user.setName("name");
user.setId("id");
user.setEmployeeId("employeeId");
user.setLike("like");
user.setField(new HashMap<>());
ObjectMapper objectMapper = new ObjectMapper();
String s1 = objectMapper.writeValueAsString(user);
System.out.println("s1 = " + s1);
Object json = JSON.parse(s1, Feature.OrderedField);
System.out.println();
}
@Data
static class User {
private String like;
private String id;
private String name;
private String employeeId;
private Map<String, Object> field;
}
@Test
void time2() throws JsonProcessingException {
User user = new User();
user.setName("name");
user.setId("id");
user.setEmployeeId("employeeId");
user.setLike("like");
HashMap<String, Object> fields = new HashMap<>();
fields.put("备注", "这是备注");
fields.put("like", "like like");
fields.put("爱好", "女");
fields.put("school", "清华");
user.setField(fields);
// Object user = getArrayArray();
Object jsonNode = JsonUtil.toJson(user);
String s = JsonUtil.toJsonString(jsonNode);
System.out.println("s = " + s);
}
}