TileSizeSaver implements ElementTypeAdapter<TileSize> { @Override public TileSize deserialize(JsonElement json, JsonDeserializationContext context) throws JsonParseException { int width = json.getAsJsonArray().get(0).getAsInt(); int height = json.getAsJsonArray().get(1).getAsInt(); try { return new TileSize(width, height); } catch (IllegalArgumentException e) { throw new JsonParseException("Illegal TileSize. Expected positive integers, found " + json.getAsString(), e); } }  @Override JsonElement serialize(TileSize src, JsonSerializationContext context); @Override TileSize deserialize(JsonElement json, JsonDeserializationContext context);  }
@Test public void deserialize() throws Exception { TileSize tileSize = gson.fromJson("[1,2]", TileSize.class); assertEquals(tileSize, new TileSize(1, 2)); }