FastJson封装的工具类
public class JsonUtils {
private static SerializeConfig config;
private static SerializerFeature[] features = {
SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullListAsEmpty,
SerializerFeature.WriteNullNumberAsZero,
SerializerFeature.WriteNullBooleanAsFalse,
SerializerFeature.WriteNullStringAsEmpty
};
static {
config = new SerializeConfig();
config.put(java.util.Date.class,new JSONLibDataFormatSerializer());
}
public static String toJSONString(Object object) {
return JSONObject.toJSONString(object,config,features);
}
public static Object toObject(String str){
return JSON.parse(str);
}
public static <T> T toObject(String str,Class<T> t){
return JSON.parseObject(str,t);
}
public static <T> List<T> toList(String str, Class<T> t){
return JSON.parseArray(str,t);
}
public static <T> Map<String,T> toMap(String str){
return (Map<String, T>) JSONObject.parseObject(str);
}
}