All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.litongjava.tio.utils.json.MixedJson Maven / Gradle / Ivy

There is a newer version: 3.7.3.v202400213-RELEASE
Show newest version
package com.litongjava.tio.utils.json;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

/**
 * JFinalJson 与 FastJson 混合做 json 转换 toJson 用 JFinalJson,parse 用 FastJson
 * 

* 注意: 1:需要添加 fastjson 相关 jar 包 2:parse 方法转对象依赖于 setter 方法 */ public class MixedJson extends Json { private TioJson tioJson; private FastJson2 fastJson; public static MixedJson getJson() { return new MixedJson(); } public String toJson(Object object) { return getJFinalJson().toJson(object); } public T parse(String jsonString, Class type) { return getFastJson().parse(jsonString, type); } private TioJson getJFinalJson() { if (tioJson == null) { tioJson = TioJson.getJson(); } if (datePattern != null) { tioJson.setDatePattern(datePattern); } return tioJson; } private FastJson2 getFastJson() { if (fastJson == null) { fastJson = FastJson2.getJson(); } if (datePattern != null) { fastJson.setDatePattern(datePattern); } return fastJson; } @Override public Map parseToMap(String json) { if (fastJson == null) { fastJson = FastJson2.getJson(); } return fastJson.parseToMap(json); } @Override public Map parseToMap(String json, Class kType, Class vType) { if (fastJson == null) { fastJson = FastJson2.getJson(); } return fastJson.parseToMap(json, kType, vType); } @Override public Object parseObject(String jsonString) { if (fastJson == null) { fastJson = FastJson2.getJson(); } return fastJson.parseObject(jsonString); } @Override public Object parseArray(String jsonString) { if (fastJson == null) { fastJson = FastJson2.getJson(); } return fastJson.parseArray(jsonString); } @Override public List> parseToListMap(String stringValue, Class kType, Class vType) { if (fastJson == null) { fastJson = FastJson2.getJson(); } return fastJson.parseToListMap(stringValue, kType, vType); } @Override public Object parse(String stringValue) { if (fastJson == null) { fastJson = FastJson2.getJson(); } return fastJson.parse(stringValue); } @Override public byte[] toJsonBytes(Object object) { if (fastJson == null) { fastJson = FastJson2.getJson(); } return fastJson.toJsonBytes(object); } @Override public T parse(String body, Type type) { if (fastJson == null) { fastJson = FastJson2.getJson(); } return fastJson.parse(body, type); } @Override public T parse(byte[] body, Type type) { if (fastJson == null) { fastJson = FastJson2.getJson(); } return fastJson.parse(body, type); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy