CenterAdapter implements JsonSerializer<Center>, JsonDeserializer<Center> { @Override public Center deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Center center = new Center(); if (json instanceof JsonArray) { JsonArray array = (JsonArray)json; if (array.size() != 2) { throw new JsonParseException("Center must be of format [x,y]"); } center.setX(array.get(0).getAsDouble()); center.setY(array.get(1).getAsDouble()); } else { throw new JsonParseException("Center must be JSON array"); } return center; }  @Override JsonElement serialize(Center src, Type typeOfSrc, JsonSerializationContext context); @Override Center deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context);  }
@Test public void deserializeTest() { JsonArray json = new JsonArray(); json.add(new JsonPrimitive(12.3)); json.add(new JsonPrimitive(4.56)); Center deserialized = centerAdapter.deserialize(json, Center.class, null); assertThat(deserialized.getX(), is(equalTo(12.3))); assertThat(deserialized.getY(), is(equalTo(4.56))); }