0

I'm looking for a Bean to Bean Mapping Java Framework that their mapping rules could be defined outside/not in java code. The source and target beans has n subBeans so the mapping rules could be a little bit complex (not a simple one-to-one mapping).

A little overview about the process: It's Simple ETL process but with a configurable mapping logic. I use Spring Batch to load a multiline record (fixed lenght file) into a bean. Its just a representation of the record as an javabean to use it as base for the defined mapping rules. the result of this mapping is another javabean that is completly different build as the source one. And here I would like to use a generic mapping framework between this to java beans.

The Spring Batch part is completly clear and implemented.

Of course I could defined it hardcoded in java but for transparence reasons I have to export this mapping logic outside the java code.

Does anyone know a such framework? Does one exists? I found Dozer but I think I can't define some complex mapping rules in their XML.

Waynn Lue
  • 11,344
  • 8
  • 51
  • 76
jny
  • 1

2 Answers2

1

Maybe. I would use the Java Scripting API for this. It allows you to load scripts (JavaScript, Beanshell, Groovy, whatever) and run them. You could put a line of input (or the whole model) in a variable and the script could then create the new object structure.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
0

try to use JMapper Framework. In XML you can write STATIC and DYNAMIC conversion using placeholders to use values and names of the fields, for example if you need to get and set values from a map the code is the follows:

<conversion name="fromMapToAll" from="map" type="DYNAMIC">
        return (${destination.type}) ${source}.get("${destination.name}");
</conversion>
<conversion name="fromAllToMap" to="map" type="DYNAMIC">
        ${destination}.put("${source.name}",${source});
        return ${destination};
</conversion>

see the wiki page for more info.

Alessandro
  • 282
  • 3
  • 10