Skip to content

API Overview

Alessandro Vurro edited this page May 17, 2016 · 7 revisions

API are useful when you want to apply loose coupling using java code or if you need to generate the configuration dynamically at runtime.

Take a look at this method:

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

public <D,S> IMapper<D, S> getMapper(Class<D> dClass, Class<S> sClass, boolean isDestMapped, Attribute... attributes){

   Class<?> clazz = isDestMapped ? dClass: sClass;

   MappedClass mappedClass = mappedClass(clazz);
   for(Attribute attribute: attributes)
       mappedClass.add(attribute);

   // or in java 8
   // Stream.of(attributes).each(attribute -> mappedClass.add(attribute));

   JMapperAPI api = new JMapperAPI().add(mappedClass);

   return new JMapper<D, S>(dClass, sClass, api);
}

This is just an example, the possible implementations are several.

####How API works

the API are not deliberately entirely fluent, in order to facilitate the composition of the configuration.
What JMapperAPI do is to facilitate the creation of xml as string, In fact, to get the equivalent xml just write the following code:

api.toXStream().toString();
Clone this wiki locally