我想存档这样的东西:
data class Task(
@JsonProperty("id", access = READ_ONLY)
val id: String?
...
<other params>
...
)
不幸的是,这会导致以下异常:
com.fasterxml.jackson.databind.JsonMappingException:
Argument #0 of constructor [constructor for Task, annotations: [null]]
has no property name annotation;
must have name when multiple-parameter constructor annotated as Creator
at [Source: {"id":"AT-5", ...}; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:305)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:268)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:476)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3899)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3794)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2842)
这个有效:
data class Task(
@JsonProperty("id")
val id: String?
)
我试过@field:JsonProperty
无济于事。
如何让这个注释在 Kotlin 中工作?我使用 dropwizard 1.1.0,杰克逊 2.8.6