I need to create a Hashmap of field/values contained in an Entity, so I can can use them to replace them in a String containing tags with the field names.
I have this code:
public static String replaceTags(String message, Map<String, String> tags) ...
Which replaces all tags found in message for the equivalent values in tags, but in order to build the Map table I need to take "any" Entity and be able to create a Map from the Entity. So, how could I make that possible? to get a routine where I send the Entity and get as return a Map with all the fields and values.
public static Map<String, String> getMapFromEntity(Object entity){
Map<String, String> map = new HashMap<String, String>();
...?????
return map;
}
I know I could use reflection and this is the only approach I have found to get this done, but is there any other way to accomplish the same?, I mean a more efficient way.
Thanks.