com.litongjava.tio.utils.json.FastJson2 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tio-utils Show documentation
Show all versions of tio-utils Show documentation
t-io is a aio framework for java
package com.litongjava.tio.utils.json;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.TypeReference;
/**
* Json 转换 fastjson 实现.
*/
public class FastJson2 extends Json {
public static FastJson2 getJson() {
return new FastJson2();
}
public String toJson(Object object) {
return JSON.toJSONString(object);
}
@Override
public byte[] toJsonBytes(Object object) {
return JSON.toJSONBytes(object);
}
/**
* 支持传入更多 SerializerFeature
*
* 例如: SerializerFeature.WriteMapNullValue 支持对 null 值字段的转换
*/
public String toJson(Object object, JSONWriter.Feature... features) {
return JSON.toJSONString(object, features);
}
public T parse(String jsonString, Class type) {
return JSON.parseObject(jsonString, type);
}
@Override
public Map, ?> parseToMap(String json) {
return JSON.parseObject(json, Map.class);
}
@Override
public Map parseToMap(String json, Class kType, Class vType) {
TypeReference