title: java reflection to create field/value hashmap
body: <p>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.</p>
  
  <p>I have this code:</p>
  
  <pre><code>public static String replaceTags(String message, Map&lt;String, String&gt; tags) ...
  </code></pre>
  
  <p>Which replaces all tags found in <strong>message</strong> for the equivalent values in <strong>tags</strong>, but in order to build the <strong>Map table</strong> 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.</p>
  
  <pre><code>public static Map&lt;String, String&gt; getMapFromEntity(Object entity){
      Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
      ...?????
  
      return map;
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>Thanks.</p>