title: How to register custom TypeAdapter or JsonDeserializer with Gson in Retrofit?
body: <p>I am using Retrofit in my project and I need some custom deserialization with some of the responses that the API I use returns.</p>
  
  <p>Just for an example: I receive JSON like: </p>
  
  <pre><code>{ "status": "7 rows processed" }
  </code></pre>
  
  <p><em>( will be "0 rows processed" if request failed )</em></p>
  
  <p>and I need to deserialize to an object like:</p>
  
  <pre><code>@Getter
  @RequiredArgsConstructor
  public static class Result {
      private final boolean success;
  }
  </code></pre>
  
  <p>I have created custom deserializer:</p>
  
  <pre><code>public class ResultDeserializer implements JsonDeserializer&lt;Result&gt; {
      @Override
      public Result deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
              throws JsonParseException {
          return new Result( ! json.getAsJsonObject().get("status").getAsString().startsWith("0"));
      }
  }
  </code></pre>
  
  <p>and I am able to test it works when I register it like:</p>
  
  <pre><code>Gson gson = new GsonBuilder().registerTypeAdapter(Result.class, new ResultDeserializer()).create(); 
  </code></pre>
  
  <p><em>NOTE: this question is meant to be canonical/Q&amp;A one and a inspired by the diffulty for me to find this when I need this information once in a year. So if the example seems to be artificial and stupid it is just because it should be simple. Hope this helps others also</em></p>