-
Notifications
You must be signed in to change notification settings - Fork 41
API Details
On this page are described in detail all the components of JMapperAPI.
in order to improve readability and simplify the implementation it is strongly recommended to import static methods provided by JMapperAPI:
...
import static com.googlecode.jmapper.api.JMapperAPI.*;
...
The starting point is JMapperAPI, you need to create it to define a configuration:
JMapperAPI api = new JMapperAPI();
An instance of api permits to do two actions: add mapped classes and print the XML as String format:
-
add(..)
takes as input an instance ofMappedClass
.
-
toXStream()
returns the bean xstream annotated, to print the xml just call the methodtoString()
on it.
To define a mapped Class what you need is create an instance of MappedClass
passing the class or a the literal name of that:
MappedClass clazz = new MappedClass(aClass.class);
//or
MappedClass clazz = new MappedClass("package.aClass");
and after add it in api instance:
api.add(clazz);
for readability is recommended to use static methods provided by JMapperAPI (in this case mappedClass
method):
api.add(mappedClass(aClass.class));
//or
api.add(mappedClass("package.aClass"));
as JMapperAPI MappedClass has only two methods:
-
add(..)
method takes as input an instance ofAttribute
,Global
orConversion
.
-
toXStream()
method returns the bean with xstream annotations, to print the xml just call the methodtoString()
on it.
To define an Attribute Class what you need is create an instance of Attribute
passing the literal name of that:
Attribute attribute = new Attribute("attributeName");
//or name with custom methods
Attribute attribute = new Attribute("attributeName","customGet","customSet");
and after add it in MappedClass
instance:
mappedClass.add(attribute);
for readability is recommended to use static methods provided by JMapperAPI (in this case attribute
method):
mappedClass.add(attribute("attributeName"));
Attribute has methods:
-
value(..)
that takes as input an instance ofTargetAttribute
or the target name as String literal.
-
targetAttributes(..)
that takes as input one or more instance ofTargetAttribute
or one or more target names as String literal.
-
targetClasses(..)
that takes as input one or more classes, the defined classes are the classes of target fields, the relationship is defined by position.
-
customGet()
that takes as input the custom get method name.
-
customSet()
that takes as input the custom set method name.
-
toXStream()
method returns the bean with xstream annotations, to print the xml just call the methodtoString()
on it.
To define a Target Attribute Class what you need is create an instance of TargetAttribute
passing the literal name of that:
TargetAttribute targetAttribute = new TargetAttribute("targetAttributeName");
//or name with custom methods
TargetAttribute targetAttribute = new TargetAttribute("targetAttributeName","customGet","customSet");
and after add it in Attribute
instance:
attribute.value(targetAttribute);
for readability is recommended to use static methods provided by JMapperAPI (in this case targetAttribute
method):
attribute.add(targetAttribute("targetAttributeName"));
TargetAttribute has methods:
-
customGet()
that takes as input the custom get method name.
-
customSet()
that takes as input the custom set method name.
-
toXStream()
method returns the bean with xstream annotations, to print the xml just call the methodtoString()
on it.
under construction
© 2016 Alessandro Vurro
- Home
- How to map
- Relations
- Conversions
- creation/enrichment
- XML
- Annotation
- API
- Configurations
- Utilities
- Examples
- Articles
- More information
- Performance tests
- Release Notes