I read some items from DB as JSON and create a Map<String, Any> from each of them. I want to process the items as Map because instantiating objects using Jackson Object Mapper's .convertValue took a long time (decimals of milliseconds more than with Map, per item). However, the type of the map is not uniform and when I need to for example get some nested prop (e.g. map.child.prop
), I need to go like this:
val prop = (parentMap["child"] as Map<String, Any>)["prop"]
I am aware there is Apache Commons providing PropertyUtils.getProperty(map, "map.child.prop"))
, but it is not exactly what I want. The object is quite complex and I need to work with the whole map as it was typed. Is there such an option? The casting goes crazy as the item is a big map, but currently the only solution I have.
What I tried:
- Convert map to class
- Too long
- Using typed map library https://github.com/broo2s/typedmap
- The map type seems to be built continuously as you add some key/value. But I am not building continuously, I am converting from JSON.
- Using Kotlin delegated properties
- Works well for flat structure, but needs to casting when going deeper.