[実践]のJavaビーンとJSONシリアライゼーションおよびデシリアライゼーションシリアライズ[]

com.fasterxml.jackson.core
ジャクソン、データバインド
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
公開された345元の記事 ウォンの賞賛2 ビュー2106

おすすめ

転載: blog.csdn.net/m0_37681589/article/details/103688135