Skip to content

Constructors

avurro edited this page Mar 22, 2016 · 8 revisions

There are many signatures of the JMapper constructor, so as to allow the definition of only the necessary values.

Basic Constructor

new JMapper <>(Destination.class, Source.class);

In this case JMapper search the annotated configuration in both classes. If both classes are configured, the framework will consider the configuration of the Destination Class.

Explicit configuration location

If you want to define which configuration to be analyze, simply pass to the constructor the ChooseConfig enumeration.

new JMapper <>(Destination.class, Source.class, ChooseConfig.SOURCE);
ChooseConfig.SOURCE it evaluates the configuration of Source
ChooseConfig.DESTINATION it evaluates the configuration of Destination

XML configuration

If you wrote the xml configuration file, you have to pass the path to the constructor, as below:

new JMapper <>(Destination.class, Source.class, "xml/jmapper.xml");

Remember the xml file must be accessible from your classpath at runtime. If you want define an external path, you need to add this prefix: file: for example:
Windows "file:/C:/path/jmapper.xml"
Unix "file:/Users/path/jmapper.xml"

XML configuration as String

If you have an xml in String format, you can pass it as input to the JMapper

String xml =
"""
<jmapper>
  <class name="it.jmapper.bean.Destination">
    <attribute name="id">
      <value name="id"/>
    </attribute>
    <attribute name="destinationField">
      <value name="sourceField">
    </attribute>
  </class>
</jmapper>
""";

new JMapper<>(Destination.class, Source.class, xml);

Constructor with all parameters

Below an example of constructor complete with all parameters:

new JMapper<>(Destination.class, Source.class, ChooseConfig.SOURCE, "xml/jmapper.xml");
Clone this wiki locally