use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project jsonschema2pojo by joelittlejohn.
the class ObjectRule method getConstructorProperties.
/**
* Retrieve the list of properties to go in the constructor from node. This
* is all properties listed in node["properties"] if ! onlyRequired, and
* only required properties if onlyRequired.
*
* @param node
* @return
*/
private LinkedHashSet<String> getConstructorProperties(JsonNode node, boolean onlyRequired) {
if (!node.has("properties")) {
return new LinkedHashSet<String>();
}
LinkedHashSet<String> rtn = new LinkedHashSet<String>();
Set<String> draft4RequiredProperties = new HashSet<String>();
// setup the set of required properties for draft4 style "required"
if (onlyRequired && node.has("required")) {
JsonNode requiredArray = node.get("required");
if (requiredArray.isArray()) {
for (JsonNode requiredEntry : requiredArray) {
if (requiredEntry.isTextual()) {
draft4RequiredProperties.add(requiredEntry.asText());
}
}
}
}
NameHelper nameHelper = ruleFactory.getNameHelper();
for (Iterator<Map.Entry<String, JsonNode>> properties = node.get("properties").fields(); properties.hasNext(); ) {
Map.Entry<String, JsonNode> property = properties.next();
JsonNode propertyObj = property.getValue();
if (onlyRequired) {
// draft3 style
if (propertyObj.has("required") && propertyObj.get("required").asBoolean()) {
rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
}
// draft4 style
if (draft4RequiredProperties.contains(property.getKey())) {
rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
}
} else {
rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
}
}
return rtn;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project hadoop by apache.
the class JHEventHandlerForSigtermTest method testCountersToJSONEmpty.
@Test(timeout = 50000)
public void testCountersToJSONEmpty() throws Exception {
JobHistoryEventHandler jheh = new JobHistoryEventHandler(null, 0);
Counters counters = null;
JsonNode jsonNode = JobHistoryEventUtils.countersToJSON(counters);
String jsonStr = new ObjectMapper().writeValueAsString(jsonNode);
String expected = "[]";
Assert.assertEquals(expected, jsonStr);
counters = new Counters();
jsonNode = JobHistoryEventUtils.countersToJSON(counters);
jsonStr = new ObjectMapper().writeValueAsString(jsonNode);
expected = "[]";
Assert.assertEquals(expected, jsonStr);
counters.addGroup("DOCTORS", "Incarnations of the Doctor");
jsonNode = JobHistoryEventUtils.countersToJSON(counters);
jsonStr = new ObjectMapper().writeValueAsString(jsonNode);
expected = "[{\"NAME\":\"DOCTORS\",\"DISPLAY_NAME\":\"Incarnations of the " + "Doctor\",\"COUNTERS\":[]}]";
Assert.assertEquals(expected, jsonStr);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project hadoop by apache.
the class JHEventHandlerForSigtermTest method testCountersToJSON.
@Test(timeout = 50000)
public void testCountersToJSON() throws Exception {
JobHistoryEventHandler jheh = new JobHistoryEventHandler(null, 0);
Counters counters = new Counters();
CounterGroup group1 = counters.addGroup("DOCTORS", "Incarnations of the Doctor");
group1.addCounter("PETER_CAPALDI", "Peter Capaldi", 12);
group1.addCounter("MATT_SMITH", "Matt Smith", 11);
group1.addCounter("DAVID_TENNANT", "David Tennant", 10);
CounterGroup group2 = counters.addGroup("COMPANIONS", "Companions of the Doctor");
group2.addCounter("CLARA_OSWALD", "Clara Oswald", 6);
group2.addCounter("RORY_WILLIAMS", "Rory Williams", 5);
group2.addCounter("AMY_POND", "Amy Pond", 4);
group2.addCounter("MARTHA_JONES", "Martha Jones", 3);
group2.addCounter("DONNA_NOBLE", "Donna Noble", 2);
group2.addCounter("ROSE_TYLER", "Rose Tyler", 1);
JsonNode jsonNode = JobHistoryEventUtils.countersToJSON(counters);
String jsonStr = new ObjectMapper().writeValueAsString(jsonNode);
String expected = "[{\"NAME\":\"COMPANIONS\",\"DISPLAY_NAME\":\"Companions " + "of the Doctor\",\"COUNTERS\":[{\"NAME\":\"AMY_POND\",\"DISPLAY_NAME\"" + ":\"Amy Pond\",\"VALUE\":4},{\"NAME\":\"CLARA_OSWALD\"," + "\"DISPLAY_NAME\":\"Clara Oswald\",\"VALUE\":6},{\"NAME\":" + "\"DONNA_NOBLE\",\"DISPLAY_NAME\":\"Donna Noble\",\"VALUE\":2}," + "{\"NAME\":\"MARTHA_JONES\",\"DISPLAY_NAME\":\"Martha Jones\"," + "\"VALUE\":3},{\"NAME\":\"RORY_WILLIAMS\",\"DISPLAY_NAME\":\"Rory " + "Williams\",\"VALUE\":5},{\"NAME\":\"ROSE_TYLER\",\"DISPLAY_NAME\":" + "\"Rose Tyler\",\"VALUE\":1}]},{\"NAME\":\"DOCTORS\",\"DISPLAY_NAME\"" + ":\"Incarnations of the Doctor\",\"COUNTERS\":[{\"NAME\":" + "\"DAVID_TENNANT\",\"DISPLAY_NAME\":\"David Tennant\",\"VALUE\":10}," + "{\"NAME\":\"MATT_SMITH\",\"DISPLAY_NAME\":\"Matt Smith\",\"VALUE\":" + "11},{\"NAME\":\"PETER_CAPALDI\",\"DISPLAY_NAME\":\"Peter Capaldi\"," + "\"VALUE\":12}]}]";
Assert.assertEquals(expected, jsonStr);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project buck by facebook.
the class TargetsCommandTest method testJsonOutputWithDirectDependencies.
@Test
public void testJsonOutputWithDirectDependencies() throws IOException {
// Run Buck targets command on a case where the deps and direct_dependencies differ
ProcessResult result = workspace.runBuckCommand("targets", "--json", "//:B");
// Parse the observed JSON.
JsonNode observed = objectMapper.readTree(objectMapper.getFactory().createParser(result.getStdout()).enable(Feature.ALLOW_COMMENTS));
// Parse the expected JSON.
String expectedJson = workspace.getFileContents("TargetsCommandTestBuckJson2.js");
JsonNode expected = objectMapper.readTree(objectMapper.getFactory().createParser(expectedJson).enable(Feature.ALLOW_COMMENTS));
assertThat("Output from targets command should match expected JSON.", observed, is(equalTo(expected)));
assertThat("Nothing should be printed to stderr.", console.getTextWrittenToStdErr(), is(equalTo("")));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project buck by facebook.
the class TargetsCommandIntegrationTest method testJsonOutputWithShowOptions.
@Test
public void testJsonOutputWithShowOptions() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "output_path", tmp);
workspace.setUp();
ProcessResult result = workspace.runBuckCommand("targets", "--json", "--show-output", "//:test");
ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
// Parse the observed JSON.
JsonNode observed = objectMapper.readTree(objectMapper.getFactory().createParser(result.getStdout()));
System.out.println(observed.toString());
String expectedJson = workspace.getFileContents("output_path_json.js");
JsonNode expected = objectMapper.readTree(objectMapper.getFactory().createParser(normalizeNewlines(expectedJson)));
MatcherAssert.assertThat("Output from targets command should match expected JSON.", observed, equalTo(expected));
}
Aggregations