Are there any mapping libraries (like Dozer) which can map from a Map<String, Object>
to a pojo/bean?
My specific use case is to map ScriptObjectMirror
s coming out of nashorn, but I should be able to work at a higher interface since ScriptObjectMirror
implements Map
.
While not exactly a duplicate, I found this question provides a straightforward answer.
In essence, Jackson's ObjectMapper
can be used for object-to-object mapping in addition to its commonly known JSON ability. The below code shows how this can easily be done in two lines.
final ObjectMapper mapper = new ObjectMapper(); // jackson's objectmapper
final MyPojo pojo = mapper.convertValue(map, MyPojo.class);