我正在使用
API 定义了一个名为
我用
我尝试使用以下注释:
Jackson 2.9.2
和 Retrofit 2.1.0
进行一些 POST
操作,其中一个 JSONArray
作为 HTML-Header
参数。API 定义了一个名为
aId
的值。无论我尝试什么,我的 JSON 属性
总是被转换为小写(aid
)。我用
abId
测试了我的相同代码,并且它可以工作... 有人知道我的配置错在哪里或者哪个约定反对这个属性名吗?//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
}]
我尝试使用以下注释:
@SerializedName("aId")
@JsonProperty("aId")
@JsonRawValue
@JsonAlias
Jackson
或JSON
相关的答案点赞,如果你认为它们值得的话。 - Michał Ziober