### Question:
NestedMetadata { public static byte[] mergedPayload(byte[] payload, byte[] metadata) throws UncheckedIOException { if (payload.length < 2 || payload[0] != '{') { throw new UncheckedIOException(new IOException("invalid json object: must start with {")); } final ByteArrayOutputStream payloadWithMetadata = new ByteArrayOutputStream( metadata.length + payload.length); payloadWithMetadata.write(metadata, 0, metadata.length - 1); if (payload.length > 2) { payloadWithMetadata.write(','); } payloadWithMetadata.write(payload, 1, payload.length - 1); return payloadWithMetadata.toByteArray(); } private  NestedMetadata(); static byte[] mergedPayload(byte[] payload, byte[] metadata); static ObjectNode attributesToMetadataPayload(Map<String, String> attributes); static void stripPayloadMetadataToAttributes(Map<String, String> attributes,
      ObjectNode payload);  }### Answer:
@Test public void testMergedPayload() throws Exception { String expect = reformatJson("{\"test\":\"foo\"}"); byte[] payload = "{}".getBytes(Charsets.UTF_8); ObjectNode node = Json.createObjectNode(); node.put("test", "foo"); byte[] actual = NestedMetadata.mergedPayload(payload, Json.asBytes(node)); assertEquals(expect, reformatJson(actual)); }
@Test(expected = UncheckedIOException.class) public void testMergedPayloadInvalidPayload() throws Exception { byte[] payload = " {}".getBytes(Charsets.UTF_8); ObjectNode node = Json.createObjectNode(); NestedMetadata.mergedPayload(payload, Json.asBytes(node)); }