Thank you for replying to the question about converting Java objects from map
flychao88 opened this issue · 0 comments
flychao88 commented
Thank you very much for your reply
My requirement is that map nested objects are converted into Java objects, and there are nested objects in objects. In this case, they cannot be copied successfully.
Null is displayed
@test
public void testMapToBean() {
Map<String, Object> map = new HashMap();
map.put("name", "abcdef");
Map<String, Object> subMap = new HashMap<>();
subMap.put("subName", "aaaaaaaa");
map.put("subUser11", subMap);
final DefaultMapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(Map.class, UserA.class)
.field("name", "name")
.field("subUser11['subName']", "subUser.subName")
.byDefault()
.register();
UserA userA = new UserA();
mapperFactory.getMapperFacade(Map.class, UserA.class).map(map,userA );
System.out.println("sub::::"+userA.getSubUser().getSubName());
}
public static class UserA {
private String name;
private SubUser subUser;
public SubUser getSubUser() {
return subUser;
}
public void setSubUser(SubUser subUser) {
this.subUser = subUser;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public static class SubUser {
public String subName;
public String getSubName() {
return subName;
}
public void setSubName(String subName) {
this.subName = subName;
}
}