Code example for JsonArray

Methods: add

public class CenterAdapter implements JsonSerializer<Center>, JsonDeserializer<Center>{
    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());
        return centerArray;
    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]");