JSONBoundingBoxInputOutputHandler implements InputHandler, OutputHandler { @Override public InputStream generate(TypedProcessOutputDescription<?> description, Data<?> data, Format format) throws IOException, EncodingException { InputStream result = null; if (data instanceof BoundingBoxData) { OwsBoundingBox boundingBox = ((BoundingBoxData) data).getPayload(); double[] lowerCorner = boundingBox.getLowerCorner(); double[] upperCorner = boundingBox.getUpperCorner(); String crs = ""; try { crs = boundingBox.getCRS().get().toString(); } catch (Exception e) { log.info("No crs present."); } ObjectNode rootNode = jsonNodeFactory.objectNode(); ArrayNode arrayNode = rootNode.arrayNode(); arrayNode.add(lowerCorner[0]); arrayNode.add(lowerCorner[1]); arrayNode.add(upperCorner[0]); arrayNode.add(upperCorner[1]); rootNode.set(BBOX, arrayNode); rootNode.put(CRS_KEY, crs); result = new ByteArrayInputStream(rootNode.toString().getBytes(Charsets.UTF_8)); } return result; } @Autowired  JSONBoundingBoxInputOutputHandler(ObjectMapper objectMapper, JsonNodeFactory jsonNodeFactory); @Override Set<Format> getSupportedFormats(); @Override Set<Class<? extends Data<?>>> getSupportedBindings(); @Override InputStream generate(TypedProcessOutputDescription<?> description, Data<?> data, Format format); @Override Data<?> parse(TypedProcessInputDescription<?> description, InputStream input, Format format);  }
@Test public void testJSONBBoxSerializer() throws IOException, EncodingException { OwsBoundingBox bbox = new OwsBoundingBox(new double[] { X_MIN, Y_MIN }, new double[] { X_MAX, Y_MAX }, EPSG_4326); BoundingBoxData data = new BoundingBoxData(bbox); try (InputStream in = handler.generate(null, data, FORMAT); InputStreamReader reader = new InputStreamReader(in, StandardCharsets.UTF_8)) { assertThat(CharStreams.toString(reader), is(equalTo(BBOX_JSON))); } }