title: How to handle escape characters in POST request in Java/JSON?
body: <p>Controller :</p>
  <pre><code>  @RequestMapping(value = {&quot;/load&quot;}, method = {RequestMethod.POST})
    public Response&lt;Void&gt; load(@RequestBody Request request) {
      try {
        service.load(request.getSqlStmt());
        return Response.success();
      } catch (SQLException ex) {
        LOGGER.info(ex);
        return Response.error(404, &quot; Load Failed for : &quot; + request.getSqlStmt());
      }
  </code></pre>
  <p>Java POJO :</p>
  <pre><code>@Data
  @NoArgsConstructor
  @AllArgsConstructor
  @Builder
  public class Request implements Serializable {
  
    private static final long serialVersionUID = 1L;
    @NotBlank private String sa;
    @NotBlank private String tableName;
    @NotBlank private String jobEnv;
    @NotBlank private String uowTo;
    @NotBlank private String sqlStmt;
    @NotBlank private String type;
  }
  </code></pre>
  <p>A) Tried without escape quotes or characters first :-</p>
  <pre><code>curl -s -k --negotiate -u : -H &quot;Content-Type: application/json&quot; -X POST -d '{&quot;sqlStmt&quot;: &quot;CALL CORE_LIB.SP_LOAD_STATUS_COMPLETE('2021-02-11',76,' ')&quot;, &quot;uowTo&quot;: &quot;20210815&quot;, &quot;tableName&quot;: &quot;tableName1&quot;, &quot;jobEnv&quot;: &quot;env1&quot;, &quot;sa&quot;: &quot;sa1&quot;, &quot;type&quot;: &quot;target&quot;}' http://example.com:443/load
  </code></pre>
  <p>SQL statement changed from &quot;CALL CORE_LIB.SP_LOAD_STATUS_COMPLETE('2021-02-11',76,' ')&quot; to CALL CORE_LIB.SP_LOAD_STATUS_COMPLETE(2021-02-11,76,) instead of CALL CORE_LIB.SP_LOAD_STATUS_COMPLETE('2021-02-11',76,'')
  The jdbc execute statement method call fails due to malformed string.</p>
  <p>B) After adding escape characters :-</p>
  <pre><code>curl -s -k --negotiate -u : -H &quot;Content-Type: application/json&quot; -X POST -d '{&quot;sqlStmt&quot;: &quot;CALL CORE_LIB.SP_LOAD_STATUS_COMPLETE(\\'2021-02-11\\',76,\\'\\')&quot;, &quot;uowTo&quot;: &quot;20210815&quot;, &quot;tableName&quot;: &quot;tableName1&quot;, &quot;jobEnv&quot;: &quot;env1&quot;, &quot;sa&quot;: &quot;sa1&quot;, &quot;type&quot;: &quot;target&quot;}' http://example.com:443/load
  </code></pre>
  <p>Error :-</p>
  <blockquote>
  <p>2021-08-17 18:17:51.823 ERROR 7 --- [http-nio-8080-exec-3]
  .e.a.d.n.e.s.c.ControllerAdvice :
  org.springframework.http.converter.HttpMessageNotReadableException:
  JSON parse error: Unrecognized character escape ‘,’ (code 44); nested
  exception is com.fasterxml.jackson.databind.JsonMappingException:
  Unrecognized character escape ‘,’ (code 44)  at [Source:
  (PushbackInputStream); line: 1, column: 66] (through reference chain:
  c.e.a.d.n.e.s.m.Request[“sqlStmt”])
  org.springframework.http.converter.HttpMessageNotReadableException:
  JSON parse error: Unrecognized character escape ‘,’ (code 44); nested
  exception is com.fasterxml.jackson.databind.JsonMappingException:
  Unrecognized character escape ‘,’ (code 44)  at [Source:
  (PushbackInputStream); line: 1, column: 66] (through reference chain:
  c.e.a.d.n.e.s.m.Request[“sqlStmt”])
  at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:275)
  ~[spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:257)
  ~[spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:205)
  ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:158)
  ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:131)
  ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
  ~[spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:167)
  ~[spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
  ~[spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
  ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
  ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
  ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
  ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
  ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
  ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
  [spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
  [spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:665) [javax.servlet-api-4.0.1.jar!/:4.0.1]
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
  [spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:750) [javax.servlet-api-4.0.1.jar!/:4.0.1]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
  [tomcat-embed-websocket-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
  [spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
  [spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
  [spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
  [spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:93)
  [spring-boot-actuator-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
  [spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
  [spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
  [spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:747)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  [na:1.8.0_242]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  [na:1.8.0_242]
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  [tomcat-embed-core-9.0.36.jar!/:9.0.36]
  at java.lang.Thread.run(Thread.java:748) [na:1.8.0_242] Caused by: com.fasterxml.jackson.databind.JsonMappingException: Unrecognized
  character escape ‘,’ (code 44)  at [Source: (PushbackInputStream);
  line: 1, column: 66] (through reference chain:
  c.e.a.d.n.e.s.m.Request[“sqlStmt”])
  at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:397)
  ~[jackson-databind-2.11.0.jar!/:2.11.0]
  at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:356)
  ~[jackson-databind-2.11.0.jar!/:2.11.0]
  at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1714)
  ~[jackson-databind-2.11.0.jar!/:2.11.0]
  at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:373)
  ~[jackson-databind-2.11.0.jar!/:2.11.0]
  at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:164)
  ~[jackson-databind-2.11.0.jar!/:2.11.0]
  at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4482)
  ~[jackson-databind-2.11.0.jar!/:2.11.0]
  at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3487)
  ~[jackson-databind-2.11.0.jar!/:2.11.0]
  at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:269)
  ~[spring-web-5.2.7.RELEASE.jar!/:5.2.7.RELEASE] Caused by:
  com.fasterxml.jackson.core.JsonParseException: Unrecognized character
  escape ‘,’ (code 44)  at [Source: (PushbackInputStream); line: 1,
  column: 66]
  at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1851)
  ~[jackson-core-2.11.0.jar!/:2.11.0]</p>
  </blockquote>
  <p>Any pointers on how I can resolve the above issue currently facing?</p>