Skip to content

Instantly share code, notes, and snippets.

@elaatifi
Created December 17, 2012 16:17
Show Gist options
  • Save elaatifi/4319530 to your computer and use it in GitHub Desktop.
Save elaatifi/4319530 to your computer and use it in GitHub Desktop.
package ma.glasnost.orika.test.community;
import java.util.Arrays;
import java.util.List;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.ConfigurableMapper;
import org.junit.Test;
public class Issue5TestCase {
@Test
public void testExcludedInList() {
MapperFacade mapper = new ConfigurableMapper() {
@Override
protected void configure(MapperFactory factory) {
super.configure(factory);
factory.classMap(A.class, C.class).exclude("excluded").byDefault().register();
}
};
B source = new B();
source.elements = Arrays.asList(newA("Hello"), newA("World"), newA("!"));
D destination = mapper.map(source, D.class);
for(C a : destination.elements) {
System.out.println(a.mapped + " : " + a.excluded);
}
}
public static A newA(String message) {
A a = new A();
a.mapped = message;
return a;
}
public static class A {
public int excluded;
public String mapped;
}
public static class B {
public List<A> elements;
}
public static class C {
public String excluded = "excluded";
public String mapped;
}
public static class D {
public List<C> elements;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment