@Test public void nestedList_serialize() throws Exception { ImmutableList<ImmutableList<Integer>> listOfLists = ImmutableList.of(ImmutableList.of(1, 2, 3), ImmutableList.of(4, 5, 6)); TypeAdapterFactory adapterFactory = new ImmutableListTypeAdapterFactory(); String json = new GsonBuilder().registerTypeAdapterFactory(adapterFactory).create().toJson(listOfLists); String expected = "[[1,2,3],[4,5,6]]"; assertEquals("json", expected, json); }
@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);  }