I'm using Jackson 2.9.2
and Retrofit 2.1.0
for some POST
operation with a JSONArray
as HTML-Header
parameter.
The API defines a value which is aId
. No matter what I try, my JSON property
is always converted to lowercase (aid
).
I tested my same code with abId
, and it works... Anyone a clue, where my configuration is wrong or which convention(?) is against this property name?
//ObjectMapper initialization
ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
//the data class
import com.fasterxml.jackson.annotation.JsonProperty
data class MyClass(
@JsonProperty
val aId: String? = null, //<-- not working
@JsonProperty
val abId: String? = null //working!
)
//Retrofit call
import retrofit2.http.Body
@POST("log")
fun sendLog(@Body logs: List<MyClass>): Call<MyCall>
//JSON Result in HTML Header
[{
"aid":"some_value", //should be "aId"
"abId":"some_value" //is correct
}]
I tried with following Annotations:
@SerializedName("aId")
@JsonProperty("aId")
@JsonRawValue
@JsonAlias
Try this @get:JsonProperty("aId")
See Michael Ziober' posted link for answer Usage of Jackson @JsonProperty annotation for kotlin data classes
Described issue is a result of Jackson's
default bahaviour to not scan private fields. This behaviour can be change with @JsonAutoDetect
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
data class MyClass(
@JsonProperty
val aId: String? = null,
@JsonProperty
val abId: String? = null
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With