問題:
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