[Pratique] java haricot et sérialisation JSON et serialize de-sérialisation []

com.fasterxml.jackson.core
jackson-DataBind
2.10.0

1, par une classe dans le projet, et l'objet peut être un format de chaîne de conversion du système 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
Publié 345 articles originaux · louange gagné 2 · Vues 2106

Je suppose que tu aimes

Origine blog.csdn.net/m0_37681589/article/details/103688135
conseillé
Classement