title: Retrofit 2.0 addConverterFactory to replace &quot with "
body: <p>in my JSON string its contain &amp;quot,</p>
  
  <pre><code>{"value":" &amp;quot;Testing&amp;quot;"}
  </code></pre>
  
  <p>If did not perform any convertion or replace of string, the default retrofit's parser doesn't take care of the escape characters, and i will have <code>&amp;quot;</code> in my result, so I found code <a href="https://stackoverflow.com/questions/26290267/retrofit-removing-some-invalid-characters-from-response-body-before-parsing-it">here</a> that help me to remove the escape characters before the retrofit's parse process, here is the modification code  </p>
  
  <pre><code>public class MyJsonConverter extends Converter.Factory {
  
  public static MyJsonConverter create() {
      return create(new Gson());
  }
  
  public static MyJsonConverter create(Gson gson) {
      return new MyJsonConverter(gson);
  }
  
  private final Gson gson;
  
  private MyJsonConverter(Gson gson) {
      if (gson == null) throw new NullPointerException("gson == null");
      this.gson = gson;
  }
  
  @Override
  public Converter&lt;ResponseBody, ?&gt; responseBodyConverter(Type type, Annotation[] annotations,
                                                          Retrofit retrofit) {
      TypeAdapter&lt;?&gt; adapter = gson.getAdapter(TypeToken.get(type));
      return new GsonResponseBodyConverter&lt;&gt;(gson, adapter);
  }
  
  @Override
  public Converter&lt;?, RequestBody&gt; requestBodyConverter(Type type,
                                                        Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
      TypeAdapter&lt;?&gt; adapter = gson.getAdapter(TypeToken.get(type));
      return new GsonRequestBodyConverter&lt;&gt;(gson, adapter);
  }
  
  
  final class GsonRequestBodyConverter&lt;T&gt; implements Converter&lt;T, RequestBody&gt; {
      private final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
      private final Charset UTF_8 = Charset.forName("UTF-8");
  
      private final Gson gson;
      private final TypeAdapter&lt;T&gt; adapter;
  
      GsonRequestBodyConverter(Gson gson, TypeAdapter&lt;T&gt; adapter) {
          this.gson = gson;
          this.adapter = adapter;
      }
  
      @Override
      public RequestBody convert(T value) throws IOException {
          Buffer buffer = new Buffer();
          Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
          JsonWriter jsonWriter = gson.newJsonWriter(writer);
          adapter.write(jsonWriter, value);
          jsonWriter.close();
          return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
      }
  }
  
  final class GsonResponseBodyConverter&lt;T&gt; implements Converter&lt;ResponseBody, T&gt; {
      private final Gson gson;
      private final TypeAdapter&lt;T&gt; adapter;
  
      GsonResponseBodyConverter(Gson gson, TypeAdapter&lt;T&gt; adapter) {
          this.gson = gson;
          this.adapter = adapter;
      }
  
      @Override
      public T convert(ResponseBody value) throws IOException {
          String dirty = value.string();
          String clean = dirty.replace("&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n" +
                  "&lt;string xmlns=\"http://tempuri.org/\"&gt;","").replace("&lt;/string&gt;","");
  
          clean = clean
                  .replace("&amp;quot;", "\"")\\This line!!!
                  .replace("\\/", "/") ;
  
          try {
              return adapter.fromJson(clean);
          } finally {
              value.close();
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>when I execute this code, it will fail later in retrofit parsing code and throw me this error</p>
  
  <blockquote>
    <p>com.google.gson.stream.MalformedJsonException: Unterminated object at
    line 1 column 1121 path
    $.entry_list[0].name_value_list.highlight1_c.value</p>
  </blockquote>
  
  <p>I understand the meaning of this error, but what is the right way to do this? And I doesn't like to replace escape characters after the retrofit Parse the Json into POJO, because that will be a lot of messy replace everywhere. Thanks for any advice.</p>