BboxAdapter implements JsonSerializer<Bbox>, JsonDeserializer<Bbox> { @Override public JsonElement serialize(Bbox src, Type typeOfSrc, JsonSerializationContext context) { JsonArray bboxArray = new JsonArray(); Envelope envelope = src.makeEnvelope(); if (envelope != null) { JsonPrimitive minx = new JsonPrimitive(envelope.getMinX()); JsonPrimitive miny = new JsonPrimitive(envelope.getMinY()); JsonPrimitive maxx = new JsonPrimitive(envelope.getMaxX()); JsonPrimitive maxy = new JsonPrimitive(envelope.getMaxY()); bboxArray.add(minx); bboxArray.add(miny); bboxArray.add(maxx); bboxArray.add(maxy); } return bboxArray; }  @Override JsonElement serialize(Bbox src, Type typeOfSrc, JsonSerializationContext context); @Override Bbox deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context);  }
@Test public void serializeTest() { Bbox bbox = new Bbox(); bbox.setId(7); bbox.setBbox(12.3, 4.56, 78.9, 8.76); JsonElement serialized = bboxAdapter.serialize(bbox, Bbox.class, null); assertThat(serialized.toString(), is(equalTo("[12.3,4.56,78.9,8.76]"))); }