jackson-databind
jackson-databind copied to clipboard
Add test case for using JsonUnwrapped on fields of the same class
See FasterXML/jackson#278 for context
I would like to include a bean into a class multiple times. For serialization, this bean should prefix its fields in a specific way so that I can reuse this bean in other classes too.
This is the JSON representation I want to use
{
"name": "name", // name.value
"name_l10n": { // name.value_l10n
"de": "name",
"fr": "nom"
},
"description": "description", // description.value
"description_l10n": { // description.value_l10n
"de": "Beschreibung",
"fr": "description"
}
}
The pairs name and name_l10n should be from the same bean instance. The java representation should be simple and reusable
public class MyFancyClass {
@JsonUnwrapped
private LocalizedField name; // → name.value and name.value_l10n
@JsonUnwrapped
private LocalizedField description; // → description.value and description.value_l10n
// ... getters and setters
}
I have provided some test cases to demonstrate the problems I have encountered so far.
- Without custom serialization configuration, the mapper creates invalid JSON. See
testUnwrappingWithDifferentProperties - Serialization works find, see
testUnwrappingWithCustomSerializer - Deserialization does not work, see
testUnwrappingWithCustomDeserializer