'Jackson: get the property name where the object is placed
I am trying to deserialize a JSON file, but I got the situation that I have to know which property is placed my deserializing object.
Look at this example:
{
...(other properties)...
"myPropertyName": {
"foo": "bar",
"baz": 123
}
}
And I want to know what is the property name where the object is placed (in this case, "myPropertyName"):
class MyObject {
@SomeAnnotation?
private String propertyName; // should get myPropertyName
private String foo; // bar
private Integer baz; // 123
// ...getters, setters...
}
Any guest?
EDIT: If helps to understand, think I'm deserializing a Map, and the json above is stored in rootStr variable:
new ObjectMapper().readValue(rootStr, new TypeReference<HashMap<String, MyObject>>() {})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
