@Test void testConvertNodeToBytes() throws Exception { final String content = "{\"someKey\":\"someValue\",\"someOther\":true}"; JsonNode node = objectMapper.readTree(content); assertArrayEquals(content.getBytes(IOUtils.UTF8), testSubject.convert(node)); }
@Override public byte[] convert(JsonNode original) { try { return objectMapper.writeValueAsBytes(original); } catch (JsonProcessingException e) { throw new CannotConvertBetweenTypesException("An error occurred while converting a JsonNode to byte[]", e); } }
JsonNodeToByteArrayConverter implements ContentTypeConverter<JsonNode,byte[]> { @Override public byte[] convert(JsonNode original) { try { return objectMapper.writeValueAsBytes(original); } catch (JsonProcessingException e) { throw new CannotConvertBetweenTypesException("An error occurred while converting a JsonNode to byte[]", e); } } }
JsonNodeToByteArrayConverter implements ContentTypeConverter<JsonNode,byte[]> { @Override public byte[] convert(JsonNode original) { try { return objectMapper.writeValueAsBytes(original); } catch (JsonProcessingException e) { throw new CannotConvertBetweenTypesException("An error occurred while converting a JsonNode to byte[]", e); } } JsonNodeToByteArrayConverter(ObjectMapper objectMapper); }
JsonNodeToByteArrayConverter implements ContentTypeConverter<JsonNode,byte[]> { @Override public byte[] convert(JsonNode original) { try { return objectMapper.writeValueAsBytes(original); } catch (JsonProcessingException e) { throw new CannotConvertBetweenTypesException("An error occurred while converting a JsonNode to byte[]", e); } } JsonNodeToByteArrayConverter(ObjectMapper objectMapper); @Override Class<JsonNode> expectedSourceType(); @Override Class<byte[]> targetType(); @Override byte[] convert(JsonNode original); }
JsonNodeToByteArrayConverter implements ContentTypeConverter<JsonNode,byte[]> { @Override public byte[] convert(JsonNode original) { try { return objectMapper.writeValueAsBytes(original); } catch (JsonProcessingException e) { throw new CannotConvertBetweenTypesException("An error occurred while converting a JsonNode to byte[]", e); } } JsonNodeToByteArrayConverter(ObjectMapper objectMapper); @Override Class<JsonNode> expectedSourceType(); @Override Class<byte[]> targetType(); @Override byte[] convert(JsonNode original);  }