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

com.litongjava.utils.json.fastjson.FastJSONSerialize Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
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> typeReference = new TypeReference>(k, v) {};
    Map map = JSON.parseObject(string, typeReference);
    return map;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy