Code example for Gson

Methods: getDelegateAdapter

0
  private static class StatsTypeAdapterFactory implements TypeAdapterFactory {
    public int numReads = 0;
    public int numWrites = 0;
 
    public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
      final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
      return new TypeAdapter<T>() {
        @Override 
        public void write(JsonWriter out, T value) throws IOException {
          ++numWrites;
          delegate.write(out, value);
        } 
 
        @Override 
        public T read(JsonReader in) throws IOException {
          ++numReads;
          return delegate.read(in);
        } 
      }; 
    } 
Contextual code suggestions in your IDE  Get Codota for Java