https://kotlinlang.org logo
#jackson-kotlin
Title
# jackson-kotlin
p

phil-t

05/06/2022, 3:22 PM
Hi, another question about deserialising with Jackson - is it possible to deserialise fields with unknown names? Here is an example which is part of a response which I want to deserialise:
Copy code
"types": {
  "10003327": {
    "typeNumber": 11,
    "classNumber": 335,
    "display": 0,
    "max": "2000",
    "name": "My type"
  }
},
The number
10003327
could be different in each response. If I was to use the data classes below I think it would work only for this example, but in another response with a different number it wouldn’t work:
Copy code
data class Response(
    val types: NumberType
)

data class NumberType(
    @JsonProperty("10003327") val typeField: Type
)

data class Type(
    val typeNumber: Int,
    val classNumber: Int,
    val display: Int,
    val max: String,
    val name: String
)
Is there a way to deserialise this completely when you don’t know what the number of the field will be, maybe with another annotation?
c

christophsturm

05/06/2022, 3:29 PM
you could use a map
☝️ 1
Map<String, Type>
p

phil-t

05/09/2022, 9:03 AM
Thanks I’ll give that a try 👍
10 Views