杰克逊克服下划线支持驼峰式 - Jackson overcoming underscores in favor of camel-case

问题:

I retrieve a JSON string from internet;我从互联网上检索了一个 JSON 字符串; like most JSON I've seen it includes long keys that are separated by underscores.像我见过的大多数 JSON 一样,它包含由下划线分隔的长键。 Essentially, my goal is to deserialize JSON into java-objects, but I don't use underscores in java-code.本质上,我的目标是将 JSON 反序列化为 java 对象,但我不在 java 代码中使用下划线。

For instance, I might have a User class with firstName field in camel-case, simultaneously I need somehow to tell Jackson to map first_name key from JSON to firstName class field.例如,我可能有一个带有驼峰式firstName字段的User类,同时我需要以某种方式告诉 Jackson 将first_name键从 JSON 映射到firstName类字段。 Is it possible?是否有可能?

class User{
    protected String firstName;
    protected String getFirstName(){return firstName;}
}

解决方案:

参考一: https://en.stackoom.com/question/i8XZ
参考二: https://stackoom.com/question/i8XZ
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章