title: Mapping some HashMap Key/Values to a POJO
body: <p>I have a HashMap of about 300 Key/String Value pairs and a POJO with about 12 string attributes where the names match the key names.</p>
  
  <p>I would like to know how to get the HashMap values into the POJO?</p>
  
  <p>I made this start which uses relfection and a loop but wasn't sure how to dynamically construct  the setter method name, and apparently reflection is a bad idea anyway...but FWIW:</p>
  
  <pre><code>    public void writeToFile(Map&lt;String, String&gt; currentSale) throws IOException {
  
      SaleExport saleExport = new SaleExport();
  
      Field[] fields = saleExport.getClass().getDeclaredFields();
  
         for (Field field : fields ) {
          System.out.println(field.getName());
          saleExport.set +field(saleExport.get(field));
  </code></pre>
  
  <p>I have used map struct once before but it does not appear to support HashMaps.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This <a href="https://stackoverflow.com/questions/16428817/convert-a-mapstring-string-to-a-pojo">answer</a> looks similar to what I want to do but gave a stack error on fields that didn't map:</p>
  
  <pre><code>Exception in thread "Thread-2" java.lang.IllegalArgumentException: Unrecognized field "Physical" (class com.SaleExport), not marked as ignorable (6 known properties: "date", "city", "surname", "streetName", "salesNo", "salesSurname"])
   at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.SalesExport["Physical"])
      at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3738)
      at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:3656)
      at com.CSVExport.writeToFile(CSVExport.java:20)
      at com.JFrameTest.writefiletoDB(JFrameTest.java:135)
      at com.JFrameTest$FileWorkerThread.run(JFrameTest.java:947)
  </code></pre>
  
  <p>To ignore the errors I tried :</p>
  
  <pre><code>mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  </code></pre>
  
  <p>But then nothing got mapped.</p>