Closed StefanLobbenmeier closed 3 years ago
Also now that I am further looking at it, why are xcoordinate and ycoordinate lowercase while contentType stayed in camelCase? (Does not matter to me though, as I want to explicitly set the name via annotation anyway)
I found out the issue - Kotlin puts the annotations on the private fields which Jackson does not scan. For writing this works:
class CoseKey(
@get:JsonProperty("1") val alg : Int = 2,
@get:JsonProperty("3") val contentType : Int = -25,
@get:JsonProperty("-1") val minus1 : Int = 1,
@get:JsonProperty("-2") val xCoordinate : ByteArray,
@get:JsonProperty("-3") val yCoordinate : ByteArray,
)
And for supporting both reading and writing remove the get: again and instead use the jackson kotlin module: https://github.com/FasterXML/jackson-module-kotlin/
I have this class:
which should read and write this key:
When I read this class from CBOR it is working just fine. But when I write it it instead produces:
Is there a different annotation I should use? In the Past I used @JsonProperty just fine for reading and writing JSON and maps, so it is strange that it here only works for reading them