title: Map Java DTO in response
body: <p>I have a Java map which I would like to map using DTO in response. I tried this:</p>
  
  <p>Service:</p>
  
  <pre><code>@Service
  public class GatewaysService {
  
      public Map&lt;Integer, String&gt; getGatewaysList() {    
          Map&lt;Integer, String&gt; list = new HashMap&lt;&gt;();    
          list.put(1, "Bogus");    
          return list;
      }
  }
  </code></pre>
  
  <p>API:</p>
  
  <pre><code>@Autowired
  private GatewaysService gatewaysService;
  
      @GetMapping("gateways")
          public ResponseEntity&lt;?&gt; getGateways() {
              return ok(gatewaysService.getGatewaysList().map(mapper::toGatewayMap));
          }
  </code></pre>
  
  <p>DTO:</p>
  
  <pre><code>public class ContractGatewaysDTO {
  
      private Integer id;
  
      private String gateway;
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public String getGateway() {
          return gateway;
      }
  
      public void setGateway(String gateway) {
          this.gateway = gateway;
      }
  }
  </code></pre>
  
  <p>Mapper:</p>
  
  <pre><code>Map&lt;Integer, String&gt; toGatewayMap(ContractGatewaysDTO dto);
  </code></pre>
  
  <p>But I get error:</p>
  
  <pre><code>The method map(ContractDTO) in the type ContractsMapper is not applicable for the arguments (mapper::toGatewayMap)
  </code></pre>
  
  <p>What is the proper way to map it? I want to convert the Java map into key-value response.</p>