convert HashMap to JavaBean instance given javabean class
is there a utility out there for creating a bean (which has simple String attributes whose name match with HashM开发者_高级运维ap keys ) given bean class as input along with properly set hashmap?
thanks, Amit
Apache Commons BeanUtils should be able to help you - since it's used for "bean" operations by many other frameworks. A "DynaBean" looks close to that.
My suggestion is to go for Dozer. I have been using it (for 3 years) for map-bean transformation and it works great. It also integrates well with Spring
Try to use mapstruct:
@Mapping(target = "beanField", source = "mapKey")
JavaBean toCustomer(Map<String, Object> map);
https://mapstruct.org/news/2021-07-18-mapstruct-1_5_0_Beta1-is-out/#mapping-from-map-to-bean
精彩评论