title: How to insert escape character i.e "\n" in json string using GSON+ java
body: <p>I am consuming a third party API using SpringBoot and Java.Their requirement is to send the JSON in below format.</p>
  
  <pre><code>"{\n" + 
              "  \"scheduleAt\": \"2020-01-16T09:45:29.361Z\",\n" + 
              "  \"serviceType\": \"TRUCK\",\n" + 
              "  \"stops\": [\n" + 
              "    {\n" + 
              "      \"location\": {\n" + 
              "        \"lat\": \"109.063753\",\n" + 
              "        \"lng\": \"312.998866\"\n" + 
              "      },\n" + 
              "      \"addresses\": {\n" + 
              "        \"en_IN\": {\n" + 
              "          \"displayString\": \"Please bring the BAG\",\n" + 
              "          \"country\": \"IN\"\n" + 
              "        }\n" + 
              "      }\n" + 
              "    }\n" + 
              "  ]\n" + 
              " }";
  </code></pre>
  
  <p>But what i am sending is this</p>
  
  <pre><code>{
    "scheduleAt": "2020-01-16T09:45:29.361Z",
    "serviceType": "TRUCK",
    "stops": [
      {
        "location": {
          "lat": "109.063753",
          "lng": "312.998866"
        },
        "addresses": {
          "en_IN": {
            "displayString": "Please bring the BAG",
            "country": "TH"
          }
        }
      }
    ]
   }
  </code></pre>
  
  <p>Can anyone please tell me how we can generate the json using GSON or any other lib so that i can get '\n' in the json. I have tried to use .toString() method but its not working. I have used .replaceAll("\n","\\n") that also does not work.</p>
  
  <p><strong>@Samabcde</strong>
  <strong>What i want is like this one.(EXPECTED)</strong></p>
  
  <pre><code>{\n \"scheduleAt\": \"2018-12-31T14:30:00.00Z\",\n \"serviceType\": \"MOTORCYCLE\",\n \"requesterContact\": { \"name\": \"Peter Pan\", \"phone\": \"232\" },\n \"stops\": [\n {\n \"location\": { \"lat\": \"-6.255431000000001\", \"lng\": \"106.60114290000001\" },\n \"addresses\": {\n \"en_ID\": {\n \"displayString\":\n \"Jl. Perum Dasana Indah No.SD 3/ 17-18, RT.3/RW.1, Bojong Nangka, Klp. Dua, Tangerang, Banten 15810, Indonesia\",\n \"country\": \"ID\"\n }\n }\n },\n {\n \"location\": { \"lat\": \"-6.404722800000001\", \"lng\": \"106.81902130000003\" },\n \"addresses\": {\n \"en_ID\": {\n \"displayString\": \"Jl. Kartini, Ruko No. 1E, Depok, Pancoran MAS, Kota Depok, Jawa Barat 16431, Indonesia\",\n \"country\": \"ID\"\n }\n }\n }\n ],\n \"deliveries\": [\n {\n \"toStop\": 1,\n \"toContact\": {\n \"name\": \"mm\",\n \"phone\": \"9999999\"\n }\n }\n ]\n}\n'
  </code></pre>
  
  <p><strong>But what actually I am getting by GSON is below:(CURRENT)</strong></p>
  
  <pre><code>{
    "scheduleAt": "2020-01-16T09:45:29.361Z",
    "serviceType": "TRUCK",
    "stops": [
      {
        "location": {
          "lat": "109.063753",
          "lng": "312.998866"
        },
        "addresses": {
          "en_IN": {
            "displayString": "Please bring the BAG",
            "country": "TH"
          }
        }
      }
    ]
   }
  </code></pre>