maxmello
08/18/2021, 2:21 PMdata class Example(@get:JsonProperty("element") val elements: List<Element> = listOf())
I remembered somehow that you need to add the get: part to a JsonProperty annotation such that it would be at the getter and not the field from Javas point of view, or else it woudn’t work right (which seems to be not the case after all), but this code above resulted in the following exception:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `int` from Array value (token `JsonToken.START_ARRAY`)
Now I strongly assume this is because List has a method get
with parameter of type Int
, but is this really how this annotation format should work? How would I even attach an annotation to the java getter in this case then?
I fixed it now by removing the get:, just curious 🤔dinomite
08/18/2021, 3:25 PMget:
is an example of a use-site target; it restricts what the annotation applies toval
or var
parameters does many things: creates a constructor parameter, creates a backing field for that parameter, and creates getters & setters@get:JsonProperty
means that the @JsonProperty
annotation will only be applied to the getter, not any of the other contextsmaxmello
08/26/2021, 9:45 AM