JsonMessageContentWrapper { byte[] wrapContent(byte[] json, String id, long timestamp, Map<String, String> externalMetadata) { try { return wrapContent(mapper.writeValueAsBytes(new MessageMetadata(timestamp, id, externalMetadata)), json); } catch (IOException e) { throw new WrappingException("Could not wrap json message", e); } } @Inject  JsonMessageContentWrapper(ConfigFactory config, ObjectMapper mapper);  JsonMessageContentWrapper(String contentRootName, String metadataRootName, ObjectMapper mapper); UnwrappedMessageContent unwrapContent(byte[] json);  }
@Test @SuppressWarnings("unchecked") public void shouldWrapJsonWithMetadata() { byte[] result = contentWrapper.wrapContent(CONTENT, metadata.getId(), metadata.getTimestamp(), externalMetadata); assertThat(readMap(result)).containsExactly(unwrappingMarker, entry("metadata", metadataAsMap), content); }