From 751818a607fa75621c7fe6e875aadfbcd77b6d5b Mon Sep 17 00:00:00 2001 From: danand Date: Tue, 12 Jan 2016 12:30:38 +0530 Subject: [PATCH 1/2] Committing a file to map list inside an object in a nested form --- .../community/ListInsideObjectMapping.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/src/main/java/ma/glasnost/orika/test/community/ListInsideObjectMapping.java diff --git a/tests/src/main/java/ma/glasnost/orika/test/community/ListInsideObjectMapping.java b/tests/src/main/java/ma/glasnost/orika/test/community/ListInsideObjectMapping.java new file mode 100644 index 00000000..265081a1 --- /dev/null +++ b/tests/src/main/java/ma/glasnost/orika/test/community/ListInsideObjectMapping.java @@ -0,0 +1,89 @@ +package ma.glasnost.orika.test.community; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import ma.glasnost.orika.MapperFactory; +import ma.glasnost.orika.test.MappingUtil; + +import org.junit.Test; + +public class Issue119TestCase { + + public static class Source { + public String id; + public SourceRef ref; + } + + public static class SourceRef { + public List identities; + public List comp1; + } + + public static class Dest { + public String id; + public DestReference references; + //public List references; + } + + public static class DestReference { + //public String identity; + public List identity; + public List comp2; + } + + public static class Complex { + + public int a; + public int b; + } + + public static class ComplexRef { + + public int aRef; + public int bRef; + } + + @Test + public void test() { + + MapperFactory factory = MappingUtil.getMapperFactory(true); + + factory.classMap(Complex.class, ComplexRef.class) + .fieldAToB("a", "aRef") + .fieldAToB("b","bRef") + .register(); + + factory.classMap(Source.class, Dest.class) + .mapNulls(false) + .fieldAToB("id", "id") + .fieldAToB("ref", "references") + .fieldAToB("ref.identities{}", "references.identity{}") + .fieldAToB("ref.comp1{}", "references.comp2{}") + .register(); + + Source src = new Source(); + src.id = "myId"; + SourceRef srcRef = new SourceRef(); + srcRef.identities = Arrays.asList("hello", "world"); + src.ref = srcRef; + Complex c1 = new Complex(); + c1.a = -100; + c1.b = -200; + srcRef.comp1 = new ArrayList(); + srcRef.comp1.add(c1); + Complex c2 = new Complex(); + c2.a = -109; + c2.b = -209; + srcRef.comp1.add(c2); + Complex c3 = new Complex(); + c3.a = 1000000; + c3.b = 5000000; + srcRef.comp1.add(c3); + + Dest dest = factory.getMapperFacade().map(src, Dest.class); + System.out.println(dest); + + } +} From 40d3f593ef0d0f1f3680f40304b9f2603ac6a199 Mon Sep 17 00:00:00 2001 From: danand Date: Tue, 12 Jan 2016 14:18:02 +0530 Subject: [PATCH 2/2] Changing class name --- .../glasnost/orika/test/community/ListInsideObjectMapping.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/main/java/ma/glasnost/orika/test/community/ListInsideObjectMapping.java b/tests/src/main/java/ma/glasnost/orika/test/community/ListInsideObjectMapping.java index 265081a1..cfb0b392 100644 --- a/tests/src/main/java/ma/glasnost/orika/test/community/ListInsideObjectMapping.java +++ b/tests/src/main/java/ma/glasnost/orika/test/community/ListInsideObjectMapping.java @@ -9,7 +9,7 @@ import org.junit.Test; -public class Issue119TestCase { +public class ListInsideObjectMapping { public static class Source { public String id;