Deserializing into Map<String, Object> based on a map-global type property #4341
-
Hi all, I need to serialize and deserialize a Map<String, Object> containing dynamic properties of different types. As such, there is no Bean-based solution possible. The possible types of properties contain Integers, Doubles, Strings, Enum values, Dates, Times, etc. Due to different constrains, it is not possible to add a type property to every single value, as it is usually done. Instead, there is a map-global property at the same level as the Map, defining a type known to the system. This type defines all possible Map entries and their types. Example: {
"type": "TypeA",
"values": {
"Key1": "AString",
"Key2": "2024-01-24"
}
...
} ... where
The serialization part is trivial, as the Java types are known. However, after trying for very long already, I simply cannot get the deserialization part working:
Any ideas please? Thank you so far, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
This sounds like a very complicate logic so your best bet may well be fully custom deserializer. |
Beta Was this translation helpful? Give feedback.
Deserializers are only given access to JSON sub-tree to specific to value they are to work on, and need to delegate "down" to values they reference. But there is no access to possible "parent" path (value being constructed -- if one already exists) or "parent" deserializer that called it.
I guess there are 2 types of delegation in existence:
BeanDeserializerModifier
comes in.Both can be used and are supported. The problem is more in that there is limited interaction between deserializers.
Having said that,
JsonParser
has method for ge…