@Test public void testToJson() throws IOException { GlobalMetadata m = new GlobalMetadata(); m.addTransferEncoding("foo"); m.addTransferEncoding("bar"); byte[] utf8 = m.toJsonUtf8(); String parsed = new String(utf8, StandardCharsets.UTF_8); JsonNode root = new ObjectMapper().readTree(parsed); Assert.assertTrue(root.isObject()); Iterator<JsonNode> children = root.getElements(); int numChildren = 0; while (children.hasNext()) { children.next(); numChildren++; } Assert.assertEquals(numChildren, 3, "expected only 3 child nodes - file, dataset, id"); Assert.assertEquals(root.get("file").size(), 0, "expected no children in file node"); Assert.assertTrue(root.get("id").isTextual(), "expected ID to be textual"); JsonNode transferEncoding = root.get("dataset").get("Transfer-Encoding"); Assert.assertEquals(transferEncoding.size(), m.getTransferEncoding().size()); for (int i = 0; i < m.getTransferEncoding().size(); i++) { Assert.assertEquals(transferEncoding.get(i).getTextValue(), m.getTransferEncoding().get(i)); } }
public String toJson() throws IOException { StringWriter writer = new StringWriter(); try (JsonGenerator generator = jsonFactory.createJsonGenerator(writer) .setCodec(objectMapper)) { toJsonUtf8(generator); } return writer.toString(); }
GlobalMetadata { public String toJson() throws IOException { StringWriter writer = new StringWriter(); try (JsonGenerator generator = jsonFactory.createJsonGenerator(writer) .setCodec(objectMapper)) { toJsonUtf8(generator); } return writer.toString(); } }
GlobalMetadata { public String toJson() throws IOException { StringWriter writer = new StringWriter(); try (JsonGenerator generator = jsonFactory.createJsonGenerator(writer) .setCodec(objectMapper)) { toJsonUtf8(generator); } return writer.toString(); } GlobalMetadata(); }
GlobalMetadata { public String toJson() throws IOException { StringWriter writer = new StringWriter(); try (JsonGenerator generator = jsonFactory.createJsonGenerator(writer) .setCodec(objectMapper)) { toJsonUtf8(generator); } return writer.toString(); } GlobalMetadata(); void markImmutable(); boolean isImmutable(); static GlobalMetadata fromJson(String json); void addAll(GlobalMetadata other); void mergeWithDefaults(GlobalMetadata defaults); byte[] toJsonUtf8(); String toJson(); String getDatasetUrn(); void setDatasetUrn(String urn); void setContentType(String contentType); String getContentType(); void setInnerContentType(String innerContentType); String getInnerContentType(); void setNumOutputFiles(int numFiles); void setNumRecords(long numRecords); Object getDatasetMetadata(String key); void setDatasetMetadata(String key, Object val); @SuppressWarnings("unchecked") List<String> getTransferEncoding(); synchronized void addTransferEncoding(String encoding); long getNumRecords(); int getNumFiles(); Object getFileMetadata(String file, String key); void setFileMetadata(String file, String key, Object val); @Override boolean equals(Object o); @Override int hashCode(); String getId(); boolean isEmpty(); }
GlobalMetadata { public String toJson() throws IOException { StringWriter writer = new StringWriter(); try (JsonGenerator generator = jsonFactory.createJsonGenerator(writer) .setCodec(objectMapper)) { toJsonUtf8(generator); } return writer.toString(); } GlobalMetadata(); void markImmutable(); boolean isImmutable(); static GlobalMetadata fromJson(String json); void addAll(GlobalMetadata other); void mergeWithDefaults(GlobalMetadata defaults); byte[] toJsonUtf8(); String toJson(); String getDatasetUrn(); void setDatasetUrn(String urn); void setContentType(String contentType); String getContentType(); void setInnerContentType(String innerContentType); String getInnerContentType(); void setNumOutputFiles(int numFiles); void setNumRecords(long numRecords); Object getDatasetMetadata(String key); void setDatasetMetadata(String key, Object val); @SuppressWarnings("unchecked") List<String> getTransferEncoding(); synchronized void addTransferEncoding(String encoding); long getNumRecords(); int getNumFiles(); Object getFileMetadata(String file, String key); void setFileMetadata(String file, String key, Object val); @Override boolean equals(Object o); @Override int hashCode(); String getId(); boolean isEmpty(); final static String DATASET_URN_KEY; final static String TRANSFER_ENCODING_KEY; final static String CONTENT_TYPE_KEY; final static String INNER_CONTENT_TYPE_KEY; final static String NUM_RECORDS_KEY; final static String NUM_FILES_KEY; }