@Test public void create() { ListHolder original = new ListHolder(); original.items = ImmutableList.of(new ListItem("beatrice", 3), new ListItem("henry", 5)); String json = gson().toJson(original); System.out.format("json:%n%s%n", json); ListHolder deserialized = gson().fromJson(json, ListHolder.class); System.out.format("deserialized:%n%s%n", deserialized); assertEquals("deserialized", original, deserialized); }
@Override public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { if (!ImmutableList.class.equals(type.getRawType())) { return null; } return (TypeAdapter<T>) createImmutableListTypeAdapter(gson, type); }
ImmutableListTypeAdapterFactory implements TypeAdapterFactory { @Override public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { if (!ImmutableList.class.equals(type.getRawType())) { return null; } return (TypeAdapter<T>) createImmutableListTypeAdapter(gson, type); } }
ImmutableListTypeAdapterFactory implements TypeAdapterFactory { @Override public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { if (!ImmutableList.class.equals(type.getRawType())) { return null; } return (TypeAdapter<T>) createImmutableListTypeAdapter(gson, type); }  }
ImmutableListTypeAdapterFactory implements TypeAdapterFactory { @Override public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { if (!ImmutableList.class.equals(type.getRawType())) { return null; } return (TypeAdapter<T>) createImmutableListTypeAdapter(gson, type); }  @Override TypeAdapter<T> create(Gson gson, TypeToken<T> type); }
ImmutableListTypeAdapterFactory implements TypeAdapterFactory { @Override public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { if (!ImmutableList.class.equals(type.getRawType())) { return null; } return (TypeAdapter<T>) createImmutableListTypeAdapter(gson, type); }  @Override TypeAdapter<T> create(Gson gson, TypeToken<T> type);  }