18

I can't find any explanation about difference between jackson's ObjectMapper to other mappers like dozer/mapStruct/modelMapping/etc. All the articles compare dozer/mapStruct/modelMapping but they ignore ObjectMapper. I can't understand what is wrong? Is the same mapper?

Plaggyy
  • 219
  • 1
  • 2
  • 8

2 Answers2

27

Dozer, MapStruct and ModelMapping are Java Bean to Java Bean mappers frameworks that recursively copies data from one object to another, property by property, field by field.

From other side, ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs, or to and from a general-purpose JSON Tree Model. ObjectMapper has some additional features like converting objects (see convertValue method) but it is not a main reason why this class was created.

So, if you want to implement sophisticated mapping between two different models you should use mappers; if you want to serialise model to JSON or deserialise model from JSON payload you have to use ObjectMapper from Jackson.

Michał Ziober
  • 37,175
  • 18
  • 99
  • 146
7

Jackson library- Mainly concerned with converting Objects/ Entities to JSON and back.

ModelMapper/ MapStruct - Concerned with mapping One entity to another like, mapping an Entity to its DTO. This operation can get pretty gnarly owing to the size and complexity of different entities, so we need these libraries to make work easier.

Prathamesh Beri
  • 131
  • 1
  • 5