-
Notifications
You must be signed in to change notification settings - Fork 41
Constructors
There are many signatures of the JMapper constructor, so as to allow the definition of only the necessary values.
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.
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");
If for a field or class there isn't a configuration, JMapper will search among the annotations if they exist.
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"
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);
It suggest to make the import of the static methods.
...
import static com.googlecode.jmapper.api.JMapperAPI.*;
...
JMapperAPI jmapperAPI = new JMapperAPI()
.add(mappedClass(Destination.class)
.add(attribute("id")
.value("id"))
.add(attribute("destinationField")
.value("sourceField"))
);
new JMapper <>(Destination.class, Source.class, jmapperAPI);
As XML, if for a field or class there isn't a configuration, JMapper will search among the annotations if they exist.
If you want to define which configuration to be analyze, simply pass to the constructor the ChooseConfig
enumeration.
For each constructor previously described there is an equal constructor plus ChooseConfig parameter.
For example:
new JMapper <>(Destination.class, Source.class, ChooseConfig.SOURCE);
ChooseConfig.SOURCE | it evaluates the configuration of Source |
ChooseConfig.DESTINATION | it evaluates the configuration of Destination |
© 2016 Alessandro Vurro
- Home
- How to map
- Relations
- Conversions
- creation/enrichment
- XML
- Annotation
- API
- Configurations
- Utilities
- Examples
- Articles
- More information
- Performance tests
- Release Notes