CenterAdapter implements JsonSerializer<Center>, JsonDeserializer<Center> { @Override public JsonElement serialize(Center src, Type typeOfSrc, JsonSerializationContext context) { JsonArray centerArray = new JsonArray(); JsonPrimitive x = new JsonPrimitive(src.getX()); JsonPrimitive y = new JsonPrimitive(src.getY()); centerArray.add(x); centerArray.add(y); return centerArray; }  @Override JsonElement serialize(Center src, Type typeOfSrc, JsonSerializationContext context); @Override Center deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context);  }
@Test public void serializeTest() { Center center = new Center(); center.setId(7); center.setX(12.3); center.setY(4.56); JsonElement serialized = centerAdapter.serialize(center, Center.class, null); assertThat(serialized.toString(), is(equalTo("[12.3,4.56]"))); }