title: How to parse an application/json object into a String
body: <p>I am programmatically navigating to a site that returns application/json format. I can't seem to read the json returned in the HttpURLConnection. I am using Jackson to demarshall the JSON into the java object. The code is:</p>
  
  <pre><code>InputStreamReader isr = new InputStreamReader(connection.getInputStream());
  BufferedReader br = new BufferedReader(isr);
  StringBuilder sb = new StringBuilder();
  String line = br.readLine();
  while (line != null) {
      sb.append(line);
      line = br.readLine();
  }
  geoLocation = (new ObjectMapper()).readValue(sb.toString(), GeoLocation.class);
  </code></pre>
  
  <p>When I print sb.toString(), I get funny looking characters and unicodes. I should get a well formed String. The resulting exception is:</p>
  
  <pre><code>org.codehaus.jackson.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
   at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@3f6dadf9; line: 1, column: 2]
      at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1291)
      at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385)
  </code></pre>
  
  <p>For example, if my url is:</p>
  
  <pre><code>http://api.ipinfodb.com/v3/ip-city/?key=&lt;mykeyhere&gt;&amp;ip=38.111.145.101&amp;format=xml
  </code></pre>
  
  <p>I get the following inside the Browser window:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Response&gt;
      &lt;statusCode&gt;OK&lt;/statusCode&gt;
      &lt;statusMessage&gt;&lt;/statusMessage&gt;
      &lt;ipAddress&gt;38.111.145.101&lt;/ipAddress&gt;
      &lt;countryCode&gt;US&lt;/countryCode&gt;
      &lt;countryName&gt;UNITED STATES&lt;/countryName&gt;
      &lt;regionName&gt;CALIFORNIA&lt;/regionName&gt;
      &lt;cityName&gt;OAKLAND&lt;/cityName&gt;
      &lt;zipCode&gt;94601&lt;/zipCode&gt;
      &lt;latitude&gt;37.7993&lt;/latitude&gt;
      &lt;longitude&gt;-122.24&lt;/longitude&gt;
      &lt;timeZone&gt;-08:00&lt;/timeZone&gt;
  &lt;/Response&gt;
  </code></pre>
  
  <p>But when I do </p>
  
  <pre><code>http://api.ipinfodb.com/v3/ip-city/?key=&lt;mykeyhere&gt;&amp;ip=38.111.145.101&amp;format=json
  </code></pre>
  
  <p>It prompts me to download a file. Once you open the file after it has been downloaded, it contains:</p>
  
  <pre><code>{
      "statusCode" : "OK",
      "statusMessage" : "",
      "ipAddress" : "38.111.145.101",
      "countryCode" : "US",
      "countryName" : "UNITED STATES",
      "regionName" : "CALIFORNIA",
      "cityName" : "OAKLAND",
      "zipCode" : "94601",
      "latitude" : "37.7993",
      "longitude" : "-122.24",
      "timeZone" : "-08:00"
  }
  </code></pre>
  
  <p>I also tried passing the input stream directly to jackson but it failed with the same result.</p>
  
  <pre><code>geoLocation = (new ObjectMapper()).readValue(urlConn.getInputStream(), GeoLocation.class);
  </code></pre>
  
  <p>Any idea how I can retrieve the JSON from the URLConn in a viewable String format so I can pass it to Jacson?</p>
  
  <p>Thank you</p>