title: Java code with POST request with newline in Json body issuing an error
body: <p>I have written a Java client for a REST server that works perfectly unless a newline is added to a String in the Json body request. The same request works perfectly with the newline if I use a client such as Insomnia. A Javascript/HTML client also works fine with the same data. In the Json sample below the problem is with the field "text". If I remove the "\n" the code works. Otherwise the server returns error 400.</p>
  
  <p>I have tried several different encodings and arguments in the request. Nothing seems to work.</p>
  
  <pre><code>Json request formated
  {
      "name": "Operation 101",
      "idPio": "10007200000000000205",
      "idGlobalPio": "5387fed1-d010-4bde-b45b-7dd5815b9e03",
      "text": "Description\n1 - First line\n2 - Second Line",
  }
  </code></pre>
  
  <p>My java code</p>
  
  <pre><code>//If I just remove the "\n" from the String below the server issues the 200 code
  //But the server will accept this string just as it is if sent form Insomnia, handling correctly the newlines.
  String jsonBody = "{\"name\": \"Operation 101\",\"idPio\": \"10007200000000000205\",\"idGlobalPio\": \"5387fed1-d010-4bde-b45b-7dd5815b9e03\",\"text\": \"Descrition\n1 - First line\n2 - Second Line\",}";
  
  url = new URL("https://10.120.43.23:8000/api/item/1.0/item/annotation/?t=E34B2A8A-0A64-469A-AE52-45E8A9885D70");
  
  HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
  
  //Add request header
  con.setRequestMethod("POST");
  con.setRequestProperty("User-Agent", "Java client");
  con.setRequestProperty("Accept-Language", "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,fr;q=0.6");
  con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); 
  con.setRequestProperty("Accept", "application/json, text/plain, */*");
  con.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
  con.setRequestProperty("Connection", "keep-alive");
  con.setDoOutput(true);
  
  //Prepare data and send
  DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  byte[] arr = jsonBody.getBytes("UTF-8");
  wr.write(arr);
  wr.flush();
  wr.close();
  int responseCode = con.getResponseCode();
  System.out.println(String.valueOf(responseCode));
  </code></pre>