@Test public void toObject() { final Map<String, Object> ad = new HashMap<>(); ad.put("street", "calle"); ad.put("number", "17"); final List<String> emails = Arrays.asList("hola@sample.com"); final List<Map<String, Object>> address = Arrays.asList(ad); final Map<String, Object> properties = new HashMap<>(); properties.put("emails", emails); properties.put("address", address); final Person object = mapper.toObject(properties); final Person other = new Person(); other.emails = emails; other.address = Arrays.asList(new Address("calle", "17")); ASSERT.that(object).isEqualTo(other); }
@Override public Person toObject(Map<String, Object> properties) { final Person object = new Person(); object.emails = (List<String>) properties.get("emails"); if (object.emails == null && !properties.containsKey("emails")) { throw new IllegalStateException("The property \"emails\" is not set."); } if (properties.get("address") != null) { final Collection<Map<String, Object>> aux = (Collection<Map<String, Object>>) properties.get("address"); final List<Address> list = new ArrayList<>(aux.size()); for (Map<String, Object> auxProperties : aux) { list.add(addressMapper.toObject(auxProperties)); } object.address = list; } else if (!properties.containsKey("address")) { throw new IllegalStateException("The property \"address\" is not set."); } else { object.address = null; } return object; }
Person implements Mapper<Person> { @Override public Person toObject(Map<String, Object> properties) { final Person object = new Person(); object.emails = (List<String>) properties.get("emails"); if (object.emails == null && !properties.containsKey("emails")) { throw new IllegalStateException("The property \"emails\" is not set."); } if (properties.get("address") != null) { final Collection<Map<String, Object>> aux = (Collection<Map<String, Object>>) properties.get("address"); final List<Address> list = new ArrayList<>(aux.size()); for (Map<String, Object> auxProperties : aux) { list.add(addressMapper.toObject(auxProperties)); } object.address = list; } else if (!properties.containsKey("address")) { throw new IllegalStateException("The property \"address\" is not set."); } else { object.address = null; } return object; } }
Person implements Mapper<Person> { @Override public Person toObject(Map<String, Object> properties) { final Person object = new Person(); object.emails = (List<String>) properties.get("emails"); if (object.emails == null && !properties.containsKey("emails")) { throw new IllegalStateException("The property \"emails\" is not set."); } if (properties.get("address") != null) { final Collection<Map<String, Object>> aux = (Collection<Map<String, Object>>) properties.get("address"); final List<Address> list = new ArrayList<>(aux.size()); for (Map<String, Object> auxProperties : aux) { list.add(addressMapper.toObject(auxProperties)); } object.address = list; } else if (!properties.containsKey("address")) { throw new IllegalStateException("The property \"address\" is not set."); } else { object.address = null; } return object; }  }
Person implements Mapper<Person> { @Override public Person toObject(Map<String, Object> properties) { final Person object = new Person(); object.emails = (List<String>) properties.get("emails"); if (object.emails == null && !properties.containsKey("emails")) { throw new IllegalStateException("The property \"emails\" is not set."); } if (properties.get("address") != null) { final Collection<Map<String, Object>> aux = (Collection<Map<String, Object>>) properties.get("address"); final List<Address> list = new ArrayList<>(aux.size()); for (Map<String, Object> auxProperties : aux) { list.add(addressMapper.toObject(auxProperties)); } object.address = list; } else if (!properties.containsKey("address")) { throw new IllegalStateException("The property \"address\" is not set."); } else { object.address = null; } return object; }  @Override Person toObject(Map<String, Object> properties); @Override Map<String, Object> toProperties(Person object); }
Person implements Mapper<Person> { @Override public Person toObject(Map<String, Object> properties) { final Person object = new Person(); object.emails = (List<String>) properties.get("emails"); if (object.emails == null && !properties.containsKey("emails")) { throw new IllegalStateException("The property \"emails\" is not set."); } if (properties.get("address") != null) { final Collection<Map<String, Object>> aux = (Collection<Map<String, Object>>) properties.get("address"); final List<Address> list = new ArrayList<>(aux.size()); for (Map<String, Object> auxProperties : aux) { list.add(addressMapper.toObject(auxProperties)); } object.address = list; } else if (!properties.containsKey("address")) { throw new IllegalStateException("The property \"address\" is not set."); } else { object.address = null; } return object; }  @Override Person toObject(Map<String, Object> properties); @Override Map<String, Object> toProperties(Person object); public Address addressMapper; }