com.fasterxml.jackson.core
jackson-databind
2.10.0
1、通过该项目下的某个类,可以将对象和 json格式的字符串互转。
public static String toJson(Object object){
try {
return objectMapper.writeValueAsString(object);
}
catch(Exception ex){
throw new IllegalStateException("can not write json:" + object, ex);
}
}
Open Declaration String com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(Object value) throws JsonProcessingException
Method that can be used to serialize any Java value as a String. Functionally equivalent to calling writeValue(Writer, Object) with java.io.StringWriter and constructing String, but more efficient.
Note: prior to version 2.1, throws clause included IOException; 2.1 removed it.
Parameters:
value
Throws:
JsonProcessingException