-1

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.

cacert
  • 2,677
  • 10
  • 33
  • 56

1 Answers1

-1

You should use reflection and just for each field find in your properties key and put into map.

VDanyliuk
  • 1,049
  • 8
  • 23