[Practice] java bean and json serialization and de-serialization serialize []

com.fasterxml.jackson.core
jackson-databind
2.10.0

1, by a class in the project, and the object may be a string format json system conversion.

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
Published 345 original articles · won praise 2 · Views 2106

Guess you like

Origin blog.csdn.net/m0_37681589/article/details/103688135