Skip to content

Regex Mapping

avurro edited this page Apr 14, 2016 · 8 revisions

The regex come in handy when we have to configure the fields with similar names, instead of defining relationship to relationship, using the regex we can dramatically reduce setup.
The following is a sample configuration with regex:

class Source1{

   List<String> customersIds;

   // getter and setter...
}

class Source2{

   Set<Integer> companyIds;

   // getter and setter...
}

class Source3{

   TreeSet<String> supplierIds;

   // getter and setter...
}

As you can see the fields have different structures, JMapper handles all implicitly.

class Destination{

   @JMap(".*ids$")
   List<Integer> ids;

   // getter and setter...
}

Xml configuration:

<jmapper>
  <class name="package.Destination">
    <attribute name="ids">
      <value name=".*ids$"/>
    </attribute>
  </class>
</jmapper>

API configuration:

...
import static com.googlecode.jmapper.api.JMapperAPI.*;
...

JMapperAPI jmapperAPI = new JMapperAPI()
    .add(mappedClass(Destination.class)
             .add(attribute("ids")
                     .value(".*ids$")));

You can see a complete example to the (Relational mapping)[https://github.com/jmapper-framework/jmapper-core/wiki/Relational-examples] wiki page

Clone this wiki locally