问题描述
我正在假装打我的休息电话.不幸的是,我收到的回复之一看起来像这样:
I am using feign for my rest-calls. Unfortunately one of the responses I get looks something like this:
{
"customer-id" : "0123"
}
JSON响应自动映射到我的POJO之一.该响应对象不能具有名称为"customer-id"的属性字段,因为标识符名称中不允许使用破折号(-).
The JSON response automatically gets mapped to one of my POJO's. This response object can not have a property field with the name "customer-id", as the dash (-) is not allowed in the name of an identifier.
我尝试了以下操作:
public class LookUpAccountsResponse {
@JsonProperty("customer-id")
private String customerId;
}
但是不幸的是,这不起作用.有人对如何解决这个问题有建议吗?
But unfortunately this doesn't work. Does anyone have a suggestion on how to fix this?
推荐答案
不确定为什么 JsonProperty
在您的类路径中,但请参见字段命名支持" https://github.com/google/gson/blob/master/UserGuide.md#json-field-naming-support
Not sure why JsonProperty
is on your classpath, but see "field naming support" https://github.com/google/gson/blob/master/UserGuide.md#json-field-naming-support
@SerializedName
是您想要的Gson批注
@SerializedName
is the Gson annotation you'll want
或完全切换为将 feign-jackson
依赖项与 JacksonDecoder
Or switch entirely to using the feign-jackson
dependency with a JacksonDecoder
这篇关于按键名称中带有破折号的JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!