0

I need to map many properties from two or more DTOs to common one. The original problem is that I need to use the domain model of other software in data integration layer. After research I have an idea to use "object to object mapper" framework (or create such myself). I have looked at above 10 frameworks and I still couldn't match all my criteria:

  1. Mature project with community support
  2. Definition of mappings by annotations or XML
  3. Bidirectional mapping
  4. Possibility of tuning generated mapping code
  5. Possibility of creating mappings basing on comprehensive conditions (wildcards, regexps, logical conditions)

My current candidates are Dozer (annotations, mature project), MapStruct (generated code, possibility of building comprehensive conditions), Moo (annotations, friendly SQL-like syntax) or doing it manually - unfortunately none of these matching all criteria

Could you share with me your experience in this subject? Maybe you met with similar problem and have better approach.

Thank you.

Viper
  • 597
  • 1
  • 8
  • 24
  • Do you have a JSON representation of these objects to play with? If yes you may want to consider JSON Merge Patch – fge Dec 05 '14 at 09:41
  • @fge Unfortunately I would do additional conversion to obtain JSON representation. The original concept was to use java mapper, because all objects are simple POJO. Do you think that converting to JSON will ensure more comfortable merging options? – Viper Dec 05 '14 at 09:53
  • Well, JSON Merge Patch is pretty easy, that is why I suggested it; what is more, it will allow you not to have to create POJOs on the fly which, let's be honest, is pretty painful. While I don't know your exact environment, I know that I'd go with that if I had a lot of merging to perform. – fge Dec 05 '14 at 09:57
  • @fge Thank you for fast reply. Could you recommend some tools or good practices for mapping to JSON/merging JSON objects? – Viper Dec 05 '14 at 09:59
  • Well, provided you use Jackson, you can use [one of my projects](https://github.com/fge/json-patch) (Spring uses it for instance) which supports both JSON Patch and JSON Merge Patch. If you are interested in JSON Merge Patch, you can [read the RFC](https://tools.ietf.org/html/rfc7386), it is a pretty easy read – fge Dec 05 '14 at 10:09
  • @Viper, out of interest, which of your requirements is not satisfied by MapStruct (I am contributing to it)? It doesn't support configuration by XML, but that's intentional :) Anything else you are missing? – Gunnar Sep 23 '15 at 09:33

0 Answers0