[英]Deserialize object with Jackson
I would like to know if there is an option in FasterXML Jackson (or any other pure way) to deserialize JSON in such way, that when I have JSON response from API like this:
{"id": "1234", "name": "name1"}
然后自動將其動態映射到 class 層次結構,如下所示:
class Person (
val sellerId: SellerId,
val name: String
)
class SellerId (
val id: String
)
實際上,我很有趣,主要是如何從頂級“id”進行動態反序列化:字符串到嵌套的“sellerid”,即包含此 id 的 object。
你需要:
String
-argument 構造函數/工廠方法來反序列SellerId
class 的String
值。sellerId
property with com.fasterxml.jackson.annotation.JsonAlias
or com.fasterxml.jackson.annotation.JsonProperty
annotations. 類似於: @JsonProperty("id") val sellerId: SellerId
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.