开发者

convert HashMap to JavaBean instance given javabean class

开发者 https://www.devze.com 2023-01-08 05:17 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消