title: Spring Boot POST Request specific payload not being accepted
body: <p>I have a post request handler setup in my spring boot app that is acting as a response entity. I have a hash map that contains a string value and string key. I am comparing the RequestBody param with the mapped key which should be the input that user is posting and then it spits out the mapped value.</p>
  
  <p>When I do this curl command: </p>
  
  <pre><code>curl -d "ncs|56-2629193|1972-03-28|20190218|77067|6208|3209440|self|-123|-123|-123|0.0|0.0|0.0|0.0|0.0|0.0|0.0" -H 'Content-Type: text/plain' http://localhost:9119/prediction
  </code></pre>
  
  <p>It returns with the custom entity response error message that it is the wrong payload even though it matches up with my string input contained in the hash map. </p>
  
  <pre><code>return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Inccorect payload");
  </code></pre>
  
  <p>Am I comparing the strings wrong?</p>
  
  <p>Here is controller class: </p>
  
  <pre><code>import java.io.IOException;
  import java.util.HashMap;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.validation.annotation.Validated;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  
  @Validated
  @RestController
  public class MockController {
  
      @Autowired
      MockEndPoint mockendpoint;
      @Autowired
      MockConfig mockconfig;
  
  
  
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public String index() {
          return "hello!";
      }
  
      @RequestMapping(value = "/prediction", method = RequestMethod.POST, produces = {"application/json"},consumes= "text/plain")
      public ResponseEntity&lt;String&gt; payloader(@RequestBody String params ) throws IOException{
          HashMap&lt;String,String&gt; x = mockconfig.getHM();
          if(params.equals((String) x.keySet().toArray()[0])) {
              return ResponseEntity.ok(x.get(mockconfig.input1)); 
              }
          else {
              return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Inccorect payload amount(18 parameters required");
          }
  
  
  
      }
  
  
  }
  </code></pre>
  
  <p>My config class: </p>
  
  <pre><code>import java.io.IOException;
  import java.util.HashMap;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Configuration;
  
  @Configuration
  public class MockConfig {
  
      String input1 = "ncs|56-2629193|1972-03-28|20190218|77067|6208|3209440|self|-123|-123|-123|0.0|0.0|0.0|0.0|0.0|0.0|0.0";
      String input2 = "ncp|56-2629193|1955-11-28|20181213|73630|6404|182232|self|-123|-123|-123|0.0|0.0|0.0|0.0|0.0|0.0|33.35";
      String input3 = "ncp|56-2629193|1955-11-28|20190103|73630|6404|182232|self|-123|-123|-123|0.0|0.0|0.0|0.0|0.0|0.0|33.35";
      String input4 = "ncp|56-2629193|1955-11-28|20190213|73700|6404|182232|self|-123|-123|-123|0.0|20.0|325.0|0.0|0.0|269.28|269.28";
      @Autowired
      MockEndPoint mockendpoint;
  
      private HashMap&lt;String,String&gt; hm = new HashMap&lt;String,String&gt;();
  
  
      public HashMap&lt;String,String&gt; getHM() throws IOException {
          hm = new HashMap&lt;String,String&gt;();
          hm.put(input1,mockendpoint.Payload1());
          hm.put(input2,mockendpoint.Payload2());
          hm.put(input3,mockendpoint.Payload3());
          hm.put(input4,mockendpoint.Payload4());
          return hm;
      }
  
  }
  </code></pre>
  
  <p>My endpoint class:</p>
  
  <pre><code>import java.io.File;
  import java.io.IOException;
  import java.nio.file.Files;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.util.ResourceUtils;
  
  @Configuration
  public class MockEndPoint {
  
  
  
  
  
      @Bean
      public String Payload1() throws IOException {
          File file = ResourceUtils.getFile("src/test/resources/Payload1.txt");
          String content = new String(Files.readAllBytes(file.toPath()));
          return content;
      }
  
  
      @Bean
      public String Payload2() throws IOException {
          File file = ResourceUtils.getFile("src/test/resources/Payload2.txt");
          String content = new String(Files.readAllBytes(file.toPath()));
          return content;
      }
      @Bean
      public String Payload3() throws IOException {
          File file = ResourceUtils.getFile("src/test/resources/Payload3.txt");
          String content = new String(Files.readAllBytes(file.toPath()));
          return content;
      }
      @Bean
      public String Payload4() throws IOException {
          File file = ResourceUtils.getFile("src/test/resources/Payload4.txt");
          String content = new String(Files.readAllBytes(file.toPath()));
          return content;
      }
  
  
      }
  </code></pre>
  
  <p>I'm not sure what's really causing this error but I have a feeling its coming from trying to compare the string param with the first key, maybe it doesn't like that I casted it?</p>