-
Notifications
You must be signed in to change notification settings - Fork 41
Global Mapping examples
avurro edited this page Aug 5, 2015
·
5 revisions
The global mapping permits to reduce the configuration in cases that the fields have the same name or all fields are mapped in direction to one.
We have two beans with some variables that have the same names.
@JGlobalMap(excluded={"other"})
class Destination { class Source {
String[] authors; List<String> authors;
Date releaseDate; Date releaseDate;
String releaseVersion; String releaseVersion;
String other; String other;
// getters and setters.. // getters and setters..
} }
<jmapper>
<class name="package.Destination">
<global>
<excluded>
<attribute name="other"/>
</excluded>
</global>
</class>
</jmapper>
List<String> authors = new ArrayList<String>();
authors.add("Alessandro Vurro");
authors.add("Federico De Felici");
Source source = new Source(authors, new GregorianCalendar(2013, 1, 16).getTime(), "1.4.0", "other");
JMapper<Destination, Source> mapper = new JMapper<>(Destination.class, Source.class);
Destination destination = mapper.getDestination(source);
output:
Destination [authors=[Alessandro Vurro, Federico De Felici], releaseDate=Sat Feb 16 00:00:00 CET 2013, releaseVersion=1.2.0, other=null]
We have one bean with some variables that point to a single field.
class Destination {
Double overallCost;
public Destination(){
overallCost = 0D;
}
public void setOverallCost(Double singleCost){
this.overallCost += singleCost;
}
// getter..
}
@JGlobalMap("overallCost")
class Source {
Double costEmployees;
Double costStructure;
Double costAdvertising;
// getters and setters..
}
<jmapper>
<class name="package.Source">
<global>
<value name="overallCost"/>
</global>
</class>
</jmapper>
JMapper<Destination, Source> mapper = new JMapper<>(Destination.class, Source.class);
Destination destination = mapper.getDestination(new Source(154080.80D,24000D,12570.20D));
output:
Destination [overallCost=190651.0]
© 2016 Alessandro Vurro
- Home
- How to map
- Relations
- Conversions
- creation/enrichment
- XML
- Annotation
- API
- Configurations
- Utilities
- Examples
- Articles
- More information
- Performance tests
- Release Notes