com.litongjava.utils.json.fastjson.FastJSONSerialize Maven / Gradle / Ivy
package com.litongjava.utils.json.fastjson;
import java.io.File;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
public class FastJSONSerialize {
/* 序列化list */
public static void serilizableForList(Object objList, File destination){
String string = JSON.toJSONString(objList, true);// (maps,CityEntity.class);
FileUtil.writeFile(string, destination);
}
/* 反序列化List */
public static List deserilizableForListFromFile(File source, Class clazz) {
String string = FileUtil.readFile(source);
List list = JSON.parseArray(string, clazz);
return list;
}
/* 序列化map */
public static void serilizableForMap(Object objMap, File destination) {
String string = JSON.toJSONString(objMap, true);
FileUtil.writeFile(string, destination);
}
/* 反序列化map */
public static Map deserilizableForMapFromFile(File source, Class k, Class v) {
String string = FileUtil.readFile(source);
TypeReference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy