JackJSON generation and parsing JSON

1, the leader packet
using jackjson, three packages into mesh project lib (jar package has uploaded), the screenshot shown in FIG:
Here Insert Picture Description
2, JackJsonUtils generating and parsing data json json data, code:

public class JackJsonUtils {  
    static ObjectMapper objectMapper;  
    /** 
     * 解析json 
     *  
     * @param content 
     * @param valueType 
     * @return 
     */  
    public static <T> T fromJson(String content, Class<T> valueType) {  
        if (objectMapper == null) {  
            objectMapper = new ObjectMapper();  
        }  
        try {  
            return objectMapper.readValue(content, valueType);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return null;  
    }  
  
    /** 
     * 生成json 
     *  
     * @param object 
     * @return 
     */  
    public static String toJson(Object object) {  
        if (objectMapper == null) {  
            objectMapper = new ObjectMapper();  
        }  
        try {  
            return objectMapper.writeValueAsString(object);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return null;  
    }  
}  

Guess you like

Origin blog.csdn.net/sjn0815/article/details/92622177