Code example for JsonArray

Methods: size

0
    @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]");
            } 
            // TODO check validity of bbox 
            center.setX(array.get(0).getAsDouble());
            center.setY(array.get(1).getAsDouble());
        } else { 
            throw new JsonParseException("Center must be JSON array");
        } 
        return center;
    } 
 
} 
Experience pair programming with AI  Get Codota for Java