I have a Java object obj
that has attributes obj.attr1
, obj.attr2
etc. The attributes are possibly accessed through an extra level of
Here is a really easy way to do this.
Use Jackson JSON lib to convert the object to JSON.
Then read the JSON and convert it to a Map.
The map will contain everything you want.
Here is the 4 liner
ObjectMapper om = new ObjectMapper();
StringWriter sw = new StringWriter();
om.writeValue(object, sw);
Map map = om.readValue(sw.toString(), Map.class);
And additional win of course is that this is recursive and will create maps of maps if it needs to