BboxAdapter implements JsonSerializer<Bbox>, JsonDeserializer<Bbox> { @Override public Bbox deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Bbox bbox = new Bbox(); if (json instanceof JsonArray) { JsonArray array = (JsonArray) json; if (array.size() == 4) { double minX = array.get(0).getAsDouble(); double minY = array.get(1).getAsDouble(); double maxX = array.get(2).getAsDouble(); double maxY = array.get(3).getAsDouble(); bbox.setBbox(minX, minY, maxX, maxY); } else if (array.size() == 0) { bbox.setBbox(null); } else { throw new JsonParseException("Bbox must be of format [minX,minY,maxX,maxY]"); } } else { throw new JsonParseException("Bbox must be JSON array"); } return bbox; }  @Override JsonElement serialize(Bbox src, Type typeOfSrc, JsonSerializationContext context); @Override Bbox 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)); json.add(new JsonPrimitive(78.9)); json.add(new JsonPrimitive(8.76)); Bbox deserialized = bboxAdapter.deserialize(json, Bbox.class, null); assertThat(deserialized.getBbox(), is(equalTo("BOX(12.300000 -4.560000, 78.900000 8.760000)"))); }