私はJson文字列をタイプOperationResult<String>
のオブジェクトに、KotlinでJacksonを使用して逆シリアル化しようとしています。タイプ名からクラス名を取得するにはどうすればよいですか?
は、私はそうのようなタイプのオブジェクトを作成する必要があります。
val mapper : ObjectMapper = ObjectMapper();
val type : JavaType = mapper.getTypeFactory()
.constructParametricType(*/ class of OperationResult */,,
/* class of String */);
val result : OperationResult<String> = mapper.readValue(
responseString, type);
は、私は次のことを試してみたが、彼らは動作しません。
val type : JavaType = mapper.getTypeFactory()
.constructParametricType(
javaClass<OperationResult>,
javaClass<String>); // Unresolved javaClass<T>
val type : JavaType = mapper.getTypeFactory()
.constructParametricType(
OperationResult::class,
String::class);
タイプ名からJavaクラスを取得するにはどうすればよいですか?
あなたはJackson-Kotilnモジュールを使用している必要があります。 https://github.com/FasterXML/jackson-module-kotlin –
@JaysonMinardありがとうございました。私はMavenを使ってそれをダウンロードし、そこからjarファイルを作成しました。今後もそれを使用していきます。 –
Maven Centralにアーティファクトがあり、構築する必要はありません... https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-kotlin/2.8.2 –