title: BufferedReader UTF-8 BOM
body: <p>I have a method in Java where I try to get one integer (user id) through a POST json request, this is the method:</p>
  
  <pre><code>public static Integer getUserIdOwnerOfMsg(Message msg) {
          Integer idUser = null;
          try {
              JSONObject jsonObject = new JSONObject();
              jsonObject.put("textMsg", msg.getTextMsg());
              jsonObject.put("hourMsg", msg.getHourMsg());
  
              List list = new LinkedList();
              list.addAll(Arrays.asList(jsonObject));
              String jsonString = list.toString();
  
              String urlStr = SERVER_PATH + "getUserIdOwnerOfMsgJSON.php";
              URL url = new URL(urlStr);
  
              HttpURLConnection con = (HttpURLConnection) url.openConnection();
              con.setRequestMethod("POST");
              con.setRequestProperty("User-Agent", "your user agent");
              con.setRequestProperty("Accept-Language", "sp,SP;q=0.5");
              //con.setRequestProperty("Content-Type", "text/html; charset=UTF-8");
  
              String urlParameters = "json=" + jsonString;
  
              con.setDoOutput(true);
              DataOutputStream wr = new DataOutputStream(con.getOutputStream());
              wr.writeBytes(urlParameters);
              wr.flush();
              wr.close();
  
              InputStream instream;
  
              int status = con.getResponseCode();
  
              if (status != HttpURLConnection.HTTP_OK)
                  instream = con.getErrorStream();
              else
                  instream = con.getInputStream();
  
              BufferedReader in = new BufferedReader(new InputStreamReader(instream, "UTF-8")); // ISO-8859-1
              in.mark(1);
              if(in.read() != 0xFEFF)
                  in.reset();
              String inputLine;
              StringBuilder response = new StringBuilder();
  
              while((inputLine = in.readLine()) != null)
                  response.append(inputLine);
  
              in.close();
  
              JSONObject object = new JSONObject(response.toString());
              Boolean correct = object.getBoolean("correct");
              if (correct) {
                  idUser = object.getInt("id");
  
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          }
          return  idUser;
      }
  </code></pre>
  
  <p>The problem is that the response contains a UTF-8 BOM character, on postman the result it's ok and I can see the id: (<code>{"id":"7","correct":true}</code>)</p>
  
  <p><a href="https://i.stack.imgur.com/el4lo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/el4lo.png" alt="Postman"></a></p>
  
  <p>But debugging on android studio I got the value <code>""</code> or <code>null</code> for <code>idUser</code>, I don't know why, I've tried so many ways to resolve this problem without succeed.</p>
  
  <p>Also on the <code>php</code> server side I've executed <code>echo mb_detect_encoding($idUsuario);</code> and I got <code>ASCII</code> encoding in case that could help to find the solution. </p>
  
  <p>Any help will be apreciated, thank you!</p>