Hey 👋
I had a weird behavior just now and wanted to understand it:
data 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 🤔