【发布时间】:2019-08-01 10:24:08
【问题描述】:
我使用 @JsonProperty 通过 Spring RestTemplate 的 exchange 序列化来自 JSON 的数据。
@JsonProperty("ip_address")
public String ipAddress;
@JsonProperty("port")
public Integer port;
我需要这个属性来识别属性名称的大写和小写版本,即@JsonProperty中设置的“ip_address”和“IP_ADDRESS”应该被识别。
我尝试了以下方法,但都没有成功:
@JsonFormat(with=JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)应用于类级别不适用于 GitHub 中报告的 existing issue。应用于模型类中的每个属性时也不起作用。use
MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIESon anObjectMapperbean.This example using
ObjectMapperandRestTemplate也无法使用之前项目上的示例的组合代码。
这三个都只有null 各自属性的值,因为我在模板的未知属性(也就是不同的字母大小写)上禁用了错误。
【问题讨论】:
-
您在尝试这些解决方案时是否遇到错误?
-
@AndrianekenaMoise 我更新了问题,但他们只有
null值,即当我期望“ip_address”但“IP_ADDRESS”在 JSON 中时。
标签: java json spring serialization resttemplate