title: How to utf-8 formatted data in json response
body: <p>I tried to save data in different languages. It's saved but when I tried to fetch the data using AJAX it does not give proper JSON data.</p>
  
  <p>I get the correct response when I save data in English. I face this problem when I save data in other languages. How can I solve this issue? Can anyone please help me.</p>
  
  <pre class="lang-js prettyprint-override"><code>$.ajax({
    type: paramsObj.type, //mandatory field
    url: https://blabla.com/asset/items.json_ajax=true
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
      'Cache-Control': 'no-cache',
      'Authorization': auth
    },
    async: true,
    data: paramsObj.data,
    dataType: 'json',
    cache: false,
    timeout: 120000,
    success: function(responseData) {
      paramsObj.success(responseData); //Invoke success callback method.
    },
    error: function(jqXHR, textStatus, errorThrown) {
      console.log("Error : " + textStatus);
      console.log(jqXHR.responseText);
  
    }
  });
  </code></pre>
  
  <p>After processing data in a Java controller I push my data to a JSON object and return like this</p>
  
  <pre class="lang-java prettyprint-override"><code>OutputStream out = null;
  String jsonData = jsonObj.toString();
  try {
        out = response.getOutputStream();
        response.setContentLength(jsonData.length());
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Headers", "Content-Type");
        response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
        out.write(jsonData.getBytes());
        out.flush();
  } catch (Exception ex) {
        ex.printStackTrace();
  }
  </code></pre>
  
  <p>On the controller side the JSON object is like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
    "categoryItems": {
      "Laundry": [{
        "id": 16640,
        "name": "చొక్కా",
        "shortDescription": "",
        "salesRate": 80,
        "image": "",
        "igst": 0,
        "cgst": 0,
        "sgst": 0,
        "state": "ACTIVE",
        "value0": "1",
        "value1": "No",
        "value2": "",
        "productposition": 0,
        "type": "Goods",
        "stockInHand": 0,
        "tags": "salesInfo",
        "catalog": "Laundry Catalog",
        "catalogCategory": "Laundry",
        "categoryId": 1979,
        "color": "#73ebdb ",
        "txtColor": "#000000",
        "groupId": 0
      }, {
        "id": 16641,
        "name": "తువాలు",
        "shortDescription": "",
        "salesRate": 40,
        "image": "",
        "igst": 0,
        "cgst": 0,
        "sgst": 0,
        "state": "ACTIVE",
        "value0": "1",
        "value1": "No",
        "value2": "",
        "productposition": 0,
        "type": "Goods",
        "stockInHand": 0,
        "tags": "salesInfo",
        "catalog": "Laundry Catalog",
        "catalogCategory": "Laundry",
        "categoryId": 1979,
        "color": "#73ebdb ",
        "txtColor": "#000000",
        "groupId": 0
      }, {
        "id": 16642,
        "name": "Curtain Door",
        "shortDescription": "",
        "salesRate": 0,
        "image": "",
        "igst": 0,
        "cgst": 0,
        "sgst": 0,
        "state": "ACTIVE",
        "value0": "1",
        "value1": "No",
        "value2": "",
        "productposition": 0,
        "type": "Goods",
        "stockInHand": 0,
        "tags": "",
        "catalog": "Laundry Catalog",
        "catalogCategory": "Laundry",
        "categoryId": 1979,
        "color": "#73ebdb ",
        "txtColor": "#000000",
        "groupId": 0
      }]
    },
    "categoryIds": [1978, 1979, 1980, 1981, 1982],
    "items": [],
    "groupCategoryItems": [],
    "groupItems": [],
    "taxes": []
  }
  </code></pre>
  
  <p>However, the JSON response is like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
    "categoryItems": {,
      "Laundry": [{
        "id": 16640,
        "name": "Ã Â°Å¡Ã Â±Å Ã Â°â€¢Ã Â±ÂÃ Â°â€¢Ã Â°Â¾",
        "shortDescription": "",
        "salesRate": 80,
        "image": "",
        "igst": 0,
        "cgst": 0,
        "sgst": 0,
        "state": "ACTIVE",
        "value0": "1",
        "value1": "No",
        "value2": "",
        "productposition": 0,
        "type": "Goods",
        "stockInHand": 0,
        "tags": "salesInfo",
        "catalog": "Laundry Catalog",
        "catalogCategory": "Laundry",
        "categoryId": 1979,
        "color": "#73ebdb ",
        "txtColor": "#000000",
        "groupId": 0
      }, {
        "id": 16641,
        "name": "Towel, L",
        "shortDescription": "",
        "salesRate": 40,
        "image": "fk_download",
        "igst": 0,
        "cgst": 0,
        "sgst": 0,
        "state": "ACTIVE",
        "value0": "1",
        "value1": "No",
        "value2": "",
        "productposition": 0,
        "type": "Goods",
        "stockInHand": 0,
        "tags": "salesInfo",
        "catalog": "Laundry Catalog",
        "catalogCategory": "Laundry",
        "categoryId": 1979,
        "color": "#73ebdb ",
        "txtColor": "#000000",
        "groupId": 0
      }, {
        "id": 16642,
        "name": "Curtain Door",
        "shortDescription": "",
        "salesRate": 0,
        "image": "",
        "igst": 0,
        "cgst": 0,
        "sgst": 0,
        "state": "ACTIVE",
        "value0": "1",
        "value1": "No",
        "value2": "",
        "productposition": 0,
        "type": "Goods",
        "stockInHand": 0,
        "tags": "",
        "catalog": "Laundry Catalog",
        "catalogCategory": "Laundry",
        "categoryId": 1979,
        "color": "#73ebdb ",
        "txtColor": "#000000",
        "groupId": 0
      }]
    },
    "categoryIds": [1978, 1979, 1980, 1981, 1982],
    "items": [],
    "groupCategoryItems": [],
    "groupItems": []
  </code></pre>
  
  <p>I changed the controller side code to this:</p>
  
  <pre class="lang-java prettyprint-override"><code>OutputStream out = null;
  String jsonData = jsonObj.toString();
  try {
        out = response.getOutputStream();
        response.setContentLength(jsonData.length());
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Headers", "Content-Type");
        response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        out.write(jsonData.getBytes());
        //System.out.println("---------------------");
        //System.out.println(out.toString());
        out.flush();
  } catch (Exception ex) {
        ex.printStackTrace();
  }
  </code></pre>
  
  <p>However, I get an incomplete JSON response</p>
  
  <pre class="lang-js prettyprint-override"><code>{
    "categoryItems": {
      "Dry Cleaning": [],
      "Laundry": [{
        "id": 16640,
        "name": "చొక్కా",
        "shortDescription": "",
        "salesRate": 80,
        "image": "",
        "igst": 0,
        "cgst": 0,
        "sgst": 0,
        "state": "ACTIVE",
        "value0": "1",
        "value1": "No",
        "value2": "",
        "productposition": 0,
        "type": "Goods",
        "stockInHand": 0,
        "tags": "salesInfo",
        "catalog": "Laundry Catalog",
        "catalogCategory": "Laundry",
        "categoryId": 1979,
        "color": "#73ebdb ",
        "txtColor": "#000000",
        "groupId": 0
      }, {
        "id": 16641,
        "name": "తువాలు",
        "shortDescription": "",
        "salesRate": 40,
        "image": "",
        "igst": 0,
        "cgst": 0,
        "sgst": 0,
        "state": "ACTIVE",
        "value0": "1",
        "value1": "No",
        "value2": "",
        "productposition": 0,
        "type": "Goods",
        "stockInHand": 0,
        "tags": "salesInfo",
        "catalog": "Laundry Catalog",
        "catalogCategory": "Laundry",
        "categoryId": 1979,
        "color": "#73ebdb ",
        "txtColor": "#000000",
        "groupId": 0
      }, {
        "id": 16642,
        "name": "Curtain Door",
        "shortDescription": "",
        "salesRate": 0,
        "image": "",
        "igst": 0,
        "cgst": 0,
        "sgst": 0,
        "state": "ACTIVE",
        "value0": "1",
        "value1": "No",
        "value2": "",
        "productposition": 0,
        "type": "Goods",
        "stockInHand": 0,
        "tags": "",
        "catalog": "Laundry Catalog",
        "catalogCategory": "Laundry",
        "categoryId": 1979,
        "color": "#73ebdb ",
        "txtColor": "#000000",
        "groupId": 0
      }],
      "Pressed/Iron": [],
      "Alteration": [],
      "Repairs": []
    },
    "categoryIds": [1978, 1979, 1980, 1981, 1982],
    "items": [],
    "groupCategoryItems": [],
    "gr
  </code></pre>