-
Notifications
You must be signed in to change notification settings - Fork 0
/
Json4fastJsonUtil.java
36 lines (28 loc) · 1014 Bytes
/
Json4fastJsonUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.Date;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.Lists;
/**
* 通用的基于fastjson工具类
*
* @author liyebing created on 15/10/22.
* @version $Id$
*/
public class Json4fastJsonUtil {
public static String toJson(Object obj, String dateFormat) {
JSON.DEFFAULT_DATE_FORMAT = dateFormat;
return JSON.toJSONString(obj, SerializerFeature.WriteDateUseDateFormat);
}
public static String toJson(Object obj) {
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
return JSON.toJSONString(obj, SerializerFeature.WriteDateUseDateFormat);
}
public static <T> T toBean(String json, Class<T> cls) {
return (T) JSON.parseObject(json, cls);
}
public static <T> T toBean(String json, TypeReference<?> valueTypeRef) {
return (T) JSON.parseObject(json, valueTypeRef);
}
}