Package org.dozer

Examples of org.dozer.Mapper.map()


  public void testDeepMappingWithIndexOnDestField() {
    Mapper mapper = getMapper(new String[] { "genericCollectionMapping.xml" });
    DestDeepObj src = newInstance(DestDeepObj.class);
    src.setDest5("some string value for field");

    SrcDeepObj dest = mapper.map(src, SrcDeepObj.class);
    assertEquals("some string value for field", dest.getSomeList().get(1).getEqualNamedList().get(0).getField3());
  }

  @Test
  public void testDeepMapIndexed() throws Exception {
View Full Code Here


    myPets[1] = secondPet;

    // Save the pet details into the source object
    source.setPets(myPets);

    HeadOfHouseHold dest = mapper.map(source, HeadOfHouseHold.class);
    assertEquals((source.getFamilyMembers().get(0)).getFirstName(), dest.getFirstName());
    assertEquals((source.getFamilyMembers().get(0)).getLastName(), dest.getLastName());
    assertEquals((source.getFamilyMembers().get(0)).getSalary(), dest.getSalary());
    assertEquals(source.getPets()[1].getPetName(), dest.getPetName());
    assertEquals(String.valueOf(source.getPets()[1].getPetAge()), dest.getPetAge());
View Full Code Here

    Person1 person1 = new Person1();

    person1.setFamilyName("Ganga");
    person1.setSecondFamilyName("Chacon");

    Person2 result = mapper.map(person1, Person2.class);

    assertNotNull(result);
    assertEquals("Ganga", result.getPersonNames().get(0).getFamilyName());
    assertEquals("Chacon", result.getPersonNames().get(1).getFamilyName());
  }
View Full Code Here

    source.setSalary(new Integer(15000));
    source.setPetAge("2");
    source.setOffSpringName("Ronny2");

    Family dest = newInstance(Family.class);
    mapper.map(source, dest);

    assertEquals((dest.getFamilyMembers().get(0)).getFirstName(), source.getFirstName());
    assertEquals((dest.getFamilyMembers().get(0)).getLastName(), source.getLastName());
    assertEquals((dest.getFamilyMembers().get(0)).getSalary(), source.getSalary());
    assertEquals(dest.getPets()[1].getPetName(), source.getPetName());
View Full Code Here

  public void testOneWay() {
    Mapper mapper = getMapper("oneWayMapping.xml");

    SourceClass source = newInstance(SourceClass.class, new Object[] {"A"});

    Holder holder = mapper.map(source, Holder.class);
    DestClass dest = holder.getDest();

    assertNotNull(dest);
    assertEquals("A", dest.anonymousAccessor());
  }
View Full Code Here

    InsideTestObject ito = newInstance(InsideTestObject.class);
    ito.setLabel("label");
    to.setFieldAccessibleComplexType(ito);
    String[] stringArray = new String[] { "one", "two" };
    to.setFieldAccessibleArrayToList(stringArray);
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals("fieldAccessible", top.fieldAccessible);
    assertEquals("label", top.fieldAccessibleComplexType.getLabelPrime());
    assertEquals(2, top.fieldAccessiblePrimInt);
    assertEquals("one", top.fieldAccessibleArrayToList.get(0));
    assertEquals("two", top.fieldAccessibleArrayToList.get(1));
View Full Code Here

    assertEquals(2, top.fieldAccessiblePrimInt);
    assertEquals("one", top.fieldAccessibleArrayToList.get(0));
    assertEquals("two", top.fieldAccessibleArrayToList.get(1));

    // Map Back
    TestObject toDest = mapper.map(top, TestObject.class);
    assertEquals("fieldAccessible", toDest.getFieldAccessible());
    assertEquals("label", toDest.getFieldAccessibleComplexType().getLabel());
    assertEquals(2, toDest.getFieldAccessiblePrimInt());
    assertEquals("one", toDest.getFieldAccessibleArrayToList()[0]);
    assertEquals("two", toDest.getFieldAccessibleArrayToList()[1]);
View Full Code Here

  public void testOverloadGetSetMethods() throws Exception {
    Mapper mapper = getMapper(new String[] { "fieldAttributeMapping.xml" });
    TestObject to = newInstance(TestObject.class);
    Date date = new Date();
    to.setOverloadGetField(new Date());
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals(date, top.getOverloadSetField());

    // Map Back
    TestObject toDest = (TestObject) mapper.map(top, TestObject.class);
    assertEquals(date, toDest.getOverloadGetField());
View Full Code Here

    to.setOverloadGetField(new Date());
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals(date, top.getOverloadSetField());

    // Map Back
    TestObject toDest = (TestObject) mapper.map(top, TestObject.class);
    assertEquals(date, toDest.getOverloadGetField());
  }

  @Test
  public void testFieldCreateMethod() throws Exception {
View Full Code Here

    Mapper mapper = getMapper(new String[] { "fieldAttributeMapping.xml" });
    TestObject to = newInstance(TestObject.class);
    InsideTestObject ito = newInstance(InsideTestObject.class);
    // we did not set any values. this will be set in the 'createMethod'
    to.setCreateMethodType(ito);
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals("myField", top.getCreateMethodType().getMyField());

    // Map Back
    TestObject toDest = mapper.map(top, TestObject.class);
    assertEquals("testCreateMethod", toDest.getCreateMethodType().getTestCreateMethod());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.