Given an entity class with a compound key that is managed by hibernate is there a simple way to flatten the keys properties into the object itself?
Given:
{
"key": {
"field1": 1,
"field2": 2
},
"prop": "value"
}
I would prefer this to be serialized as:
{
"field1": 1,
"field2": 2,
"prop": "value"
}
I really don’t want to have to implement JsonSerializableWithType as it’s fine at the moment, it’s just that key class I want the fields flattened.
Jackson uses reflection, and you can manipulate getters/setters. You can add
@JsonIgnoretogetKey(), and add two methodsYou may want to implement
setField1()andsetField2()as well.