How to convert a java pojo to hashmap( and reverse) not using field names but instead custom keys in an efficient manner. for instance;
Customer:
- name = aaa
- surname = bbb
will be converted to hashmap with keys below.
Hashmap:
- mykey1 : aaa
- mykey2 : bbb
The solution should be generic and work for different objects (there will be key to property mapping definitions like name -> mykey1, surname->mykey2) I have checked apache commons OGNL but did not quite understand how to get it work for such a situation.
Ps: I know this can be done with reflection, but I am asking a high level solution includings apis and frameworks.
您应该使用反射,并且只为每个字段在您的属性键中找到并放入地图中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.