1, jackson usage
(1) create ObjectMapper objects (reusable objects)
ObjectMapper om=new ObjectMapper();
(2) the object to deserialize
Student stu=om.readValue(jsonString,Student.class);
(3) a serialized object to json
JsonString jstr=om.writeValueAsString(stu);
JsonString jstr=om.writeValue(Io流,stu);
例writer w=newStringWrite();
OutputStream ot=new OutPutStream();
2, Ali's fastest fastJson
(1) serialized ApI
package com.alibaba.fastjson; public abstract class JSON {
// Java objects serialized as JSON strings, supports a variety of types and various Java basic JavaBean
public static String toJSONString(Object object,
SerializerFeature... features);
// The Java object serialization to JSON string, the string of JSON utf-8 bytes
public static byte[] toJSONBytes(Object object,
SerializerFeature... features);
// Java objects serialized to JSON string is written into a Writer
public static void writeJSONString(Writer writer,
Object object,
SerializerFeature... features);
// The Java object serialization to JSON string written into the OutputStream encoded by UTF-8
public static final int writeJSONString(OutputStream os, //
Object object, //
SerializerFeature... features); }
(2) JSON API string deserialization
package com.alibaba.fastjson; public abstract class JSON {
// deserialize JSON string JavaBean
public static <T> T parseObject(String jsonStr, Class<T> clazz, Feature... features);
// deserialize JSON string JavaBean
public static <T> T parseObject(byte[] jsonBytes,
// UTF-8 format string JSON Class <T> clazz, Feature ... features);
// JSON string deserialize generic types of JavaBean
public static <T> T parseObject(String text, TypeReference<T> type, Feature... features);
// deserialize JSON string is JSONObject
public static JSONObject parseObject(String text); }