lightcouch / LightCouch

CouchDB Java API
www.lightcouch.org
Apache License 2.0
67 stars 70 forks source link

using platform encoding in http get request results in wrong umlauts #36

Closed willie68 closed 9 years ago

willie68 commented 9 years ago

Writing strings with umlauts is ok, but reading umlauts will result in wrong encoding. This is an issue mainly in windows enviroments. Because the default encoding of the jvm is there cp1252. But for json it must be UTF-8. Solving this issue is simple: Just set encodig to "UTF-8" of the InputStreamReader in the get method in the CouchDbClientBase.java.

/**
   * Performs a HTTP GET request. 
   * @return An object of type T
   */
  <T> T get(URI uri, Class<T> classType) {
    InputStream in = null;
    try {
      in = get(uri);
      return getGson().fromJson(new InputStreamReader(in, "UTF-8"), classType);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    } finally {
      close(in);
    }
    return null;
  }
ahmedyha commented 9 years ago

Fixed in 0.1.8