Deep dive in to BeanUtilsBean .populate

Map<String, Object> map = new HashMap<>();
map.put("name", "Samuel")
map.put("address", " 12333 Hay ...... QLD 4743")
@Data
public class Person {
private String name;
private String address
}//Simple use of BeanUtilsBean is
Person person = new Person();
BeanUtilsBean.populate(person, map);

What is Keys and different

Map<String, Object> map = new HashMap<>();
map.put("personName", "Samuel")
map.put("personAddress", " 12333 Hay ...... QLD 4743")
Map<String, Object> newMap = new HashMap<>();
map.forEach((k, v) -> {
if(x.equals("personName")) {
newMap.put("name", v);
}else if(x.equals("personAddress")) {
newMap.put("address", v);
}
}
);
@Data
public class Person {
private String name;
private String address
private LocalDate dateOfBirth;
private SEX sex;
}public enum Sex {
MALE("Male"),

FEMALE("Female")
...
}
class MyDateConverter implements Converter {

@Override
public Object convert(Class Date, Object value) {

if(value!=null) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("soem date pattern string");
ZonedDateTime zonedDateTime = ZonedDateTime.parse(value.toString(), dtf);
return zonedDateTime.toLocalDate();
}
}
}
And register as BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
beanUtilsBean.getConvertUtils().register(new MyDateConverter(), LocalDate.class);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store