@Unwrapped for Map-like types
Hello.
It would be nice to support @Unwrapped annotation for fields of Map-like type to include arbitrary fields in serialized BSON and deserialize them back.
For example:
@Data
@Document
public class TestEntity {
private String id;
@Unwrapped(onEmpty = USE_NULL)
private Map<String, Integer> data;
}
This object
TestEntity testEntity = new TestEntity();
testEntity.setId("123");
testEntity.setData(Map.of("foo", 1, "bar", 2));
should be transformed to following json and vice versa:
{
"id": "123",
"foo": 1,
"bar": 2
}
Thanks @Stingray42 for raising the topic. Will take it to the team.
Though the idea is interesting we do not plan to add this feature. Matching properties against the keys within the document to figure out the ones that need to go into the map does not fit well with how the mapping layer works and how it is intended to work.
Sad, but understandable. Guess I will stick with BeforeSaveCallback/AfterConvertCallback pair that do the stuff.
I would've liked this feature as well, surprised that it didn't work.