引入
pom
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.1.40</version> </dependency>
public class FastJsonUtil { public static String toJson(Object obj, SerializerFeature... serializerFeature) { return JSON.toJSONString(obj, serializerFeature); } public static String toJson(Object obj) { return JSON.toJSONString(obj, SerializerFeature.DisableCircularReferenceDetect); } public static <T> T fromJson(String json, Class<T> clazz) { return JSON.parseObject(json, clazz); } public static <T> T fromJsons(String json, TypeReference<T> clazz) { return JSON.parseObject(json, clazz); } }