@Test public void deserializeImmutableList() throws Exception { Type type = new TypeToken<ImmutableList<String>>(){}.getType(); ImmutableList<String> list = new GsonBuilder() .registerTypeAdapterFactory(new ImmutableListTypeAdapterFactory()) .create() .fromJson("[\"a\", \"b\", \"c\"]", type); assertEquals(ImmutableList.of("a", "b", "c"), list); }
@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);  }