class CollectionsDeserializationBenchmark {

  private static final TypeToken<List<BagOfPrimitives>> LIST_TYPE_TOKEN =
      new TypeToken<List<BagOfPrimitives>>() {};
  private static final Type LIST_TYPE = LIST_TYPE_TOKEN.getType();
  private Gson gson;
  private String json;

  public static void main(String[] args) {
    NonUploadingCaliperRunner.run(CollectionsDeserializationBenchmark.class, args);
  }

  @BeforeExperiment
  void setUp() throws Exception {
    this.gson = new Gson();
    List<BagOfPrimitives> bags = new ArrayList<>();
    for (int i = 0; i < 100; ++i) {
      bags.add(new BagOfPrimitives(10L, 1, false, "foo"));
    }
    this.json = gson.toJson(bags, LIST_TYPE);
  }

  /** Benchmark to measure Gson performance for deserializing an object */
  public void timeCollectionsDefault(int reps) {<FILL_FUNCTION_BODY>}

  /** Benchmark to measure deserializing objects by hand */
  @SuppressWarnings("ModifiedButNotUsed")
  public void timeCollectionsStreaming(int reps) throws IOException {
    for (int i = 0; i < reps; ++i) {
      StringReader reader = new StringReader(json);
      JsonReader jr = new JsonReader(reader);
      jr.beginArray();
      List<BagOfPrimitives> bags = new ArrayList<>();
      while (jr.hasNext()) {
        jr.beginObject();
        long longValue = 0;
        int intValue = 0;
        boolean booleanValue = false;
        String stringValue = null;
        while (jr.hasNext()) {
          String name = jr.nextName();
          if (name.equals("longValue")) {
            longValue = jr.nextLong();
          } else if (name.equals("intValue")) {
            intValue = jr.nextInt();
          } else if (name.equals("booleanValue")) {
            booleanValue = jr.nextBoolean();
          } else if (name.equals("stringValue")) {
            stringValue = jr.nextString();
          } else {
            throw new IOException("Unexpected name: " + name);
          }
        }
        jr.endObject();
        bags.add(new BagOfPrimitives(longValue, intValue, booleanValue, stringValue));
      }
      jr.endArray();
    }
  }

  /**
   * This benchmark measures the ideal Gson performance: the cost of parsing a JSON stream and
   * setting object values by reflection. We should strive to reduce the discrepancy between this
   * and {@link #timeCollectionsDefault(int)} .
   */
  @SuppressWarnings("ModifiedButNotUsed")
  public void timeCollectionsReflectionStreaming(int reps) throws Exception {
    for (int i = 0; i < reps; ++i) {
      StringReader reader = new StringReader(json);
      JsonReader jr = new JsonReader(reader);
      jr.beginArray();
      List<BagOfPrimitives> bags = new ArrayList<>();
      while (jr.hasNext()) {
        jr.beginObject();
        BagOfPrimitives bag = new BagOfPrimitives();
        while (jr.hasNext()) {
          String name = jr.nextName();
          for (Field field : BagOfPrimitives.class.getDeclaredFields()) {
            if (field.getName().equals(name)) {
              Class<?> fieldType = field.getType();
              if (fieldType.equals(long.class)) {
                field.setLong(bag, jr.nextLong());
              } else if (fieldType.equals(int.class)) {
                field.setInt(bag, jr.nextInt());
              } else if (fieldType.equals(boolean.class)) {
                field.setBoolean(bag, jr.nextBoolean());
              } else if (fieldType.equals(String.class)) {
                field.set(bag, jr.nextString());
              } else {
                throw new RuntimeException("Unexpected: type: " + fieldType + ", name: " + name);
              }
            }
          }
        }
        jr.endObject();
        bags.add(bag);
      }
      jr.endArray();
    }
  }
}

    for (int i = 0; i < reps; ++i) {
      gson.fromJson(json, LIST_TYPE_TOKEN);
    }
  
<no_super_class>