简体   繁体   English

将 Json 反序列化为 Pojo,不区分大小写

[英]Deserialize Json to Pojo without case sensitivity

I have been trying to figure out how to deserialize json coming from an API response to models and ignore case.我一直在试图弄清楚如何反序列化来自 API 对模型的响应并忽略大小写的 json。 I can get it to work with something like this:我可以让它与这样的东西一起工作:

Json: Json:

{
    "Name": "foo"
}

Model: Model:

@Data
public class Member {
    @JsonProperty("Name")
    private String name;
}

I have SOOOO many because for some reason the API returns properties in pascal case rather than camel.我有很多,因为由于某种原因 API 以帕斯卡而不是骆驼的形式返回属性。 I dont really want to create a new mapper for something so trivial.我真的不想为如此琐碎的事情创建一个新的映射器。 I was hoping there was some property in spring boot that I could add to my applicaition yaml file.我希望 spring 启动中有一些属性可以添加到我的应用程序 yaml 文件中。

Any ideas?有任何想法吗?

Try configuring like below it will work:)尝试像下面这样配置它会起作用:)

@JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
private String name;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM