FastJson 使用笔记

前端之家收集整理的这篇文章主要介绍了FastJson 使用笔记前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

参考这篇文章 http://blog.csdn.net/u011425751/article/details/51219242

- - - ----------------------------------------------------------------------------------------------------------------------------

以下是Jackson使用



实体类注意注解:
@JsonProperty("nickname")
private String nickname;

public class JsonUtil { private static ObjectMapper mapper; public static void init() { mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES,false); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERscoreS); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")); } /** * 根据json格式转换对象 * @param content * @param valueType * @param <T> * @return * @throws IOException */ public static <T> T readValue(String content,Class<T> valueType) throws IOException { if(mapper == null){ init(); } return mapper.readValue(content,valueType); } /** * 将对象转换成json格式 * @param value * @return * @throws JsonProcessingException */ public static String writeValueAsString(Object value) throws JsonProcessingException { if(mapper == null){ init(); } return mapper.writeValueAsString(value); } }
原文链接:https://www.f2er.com/json/288989.html

猜你在找的Json相关文章