use of com.fasterxml.jackson.databind.JsonNode in project jsonschema2pojo by joelittlejohn.
the class MediaIT method roundTripAssertions.
public static void roundTripAssertions(ObjectMapper objectMapper, String propertyName, String jsonValue, Object javaValue) throws Exception {
ObjectNode node = objectMapper.createObjectNode();
node.put(propertyName, jsonValue);
Object pojo = objectMapper.treeToValue(node, classWithMediaProperties);
Method getter = new PropertyDescriptor(propertyName, classWithMediaProperties).getReadMethod();
assertThat(getter.invoke(pojo), is(equalTo(javaValue)));
JsonNode jsonVersion = objectMapper.valueToTree(pojo);
assertThat(jsonVersion.get(propertyName).asText(), is(equalTo(jsonValue)));
}
use of com.fasterxml.jackson.databind.JsonNode in project jsonschema2pojo by joelittlejohn.
the class PropertiesIT method propertyNamesAreLowerCamelCase.
@Test
public void propertyNamesAreLowerCamelCase() throws Exception {
ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/propertiesAreUpperCamelCase.json", "com.example");
Class<?> generatedType = resultsClassLoader.loadClass("com.example.UpperCase");
Object instance = generatedType.newInstance();
new PropertyDescriptor("property1", generatedType).getWriteMethod().invoke(instance, "1");
new PropertyDescriptor("propertyTwo", generatedType).getWriteMethod().invoke(instance, 2);
new PropertyDescriptor("propertyThreeWithSpace", generatedType).getWriteMethod().invoke(instance, "3");
new PropertyDescriptor("propertyFour", generatedType).getWriteMethod().invoke(instance, "4");
JsonNode jsonified = mapper.valueToTree(instance);
assertNotNull(generatedType.getDeclaredField("property1"));
assertNotNull(generatedType.getDeclaredField("propertyTwo"));
assertNotNull(generatedType.getDeclaredField("propertyThreeWithSpace"));
assertNotNull(generatedType.getDeclaredField("propertyFour"));
assertThat(jsonified.has("Property1"), is(true));
assertThat(jsonified.has("PropertyTwo"), is(true));
assertThat(jsonified.has(" PropertyThreeWithSpace"), is(true));
assertThat(jsonified.has("propertyFour"), is(true));
}
use of com.fasterxml.jackson.databind.JsonNode in project pinot by linkedin.
the class AutoLoadPinotMetricsService method loadDatasets.
/**
* Reads all table names in pinot, and loads their schema
* @throws IOException
*/
private void loadDatasets() throws IOException {
JsonNode tables = autoLoadPinotMetricsUtils.getAllTablesFromPinot();
for (JsonNode table : tables) {
String dataset = table.asText();
Schema schema = autoLoadPinotMetricsUtils.getSchemaFromPinot(dataset);
if (schema != null) {
if (!autoLoadPinotMetricsUtils.verifySchemaCorrectness(schema)) {
LOG.info("Skipping {} due to incorrect schema", dataset);
} else {
allDatasets.add(dataset);
allSchemas.put(dataset, schema);
}
}
}
}
use of com.fasterxml.jackson.databind.JsonNode in project pinot by linkedin.
the class AutoLoadPinotMetricsUtils method getAllTablesFromPinot.
public JsonNode getAllTablesFromPinot() throws IOException {
HttpGet tablesReq = new HttpGet(PINOT_TABLES_ENDPOINT);
LOG.info("Retrieving datasets: {}", tablesReq);
CloseableHttpResponse tablesRes = pinotControllerClient.execute(pinotControllerHost, tablesReq);
JsonNode tables = null;
try {
if (tablesRes.getStatusLine().getStatusCode() != 200) {
throw new IllegalStateException(tablesRes.getStatusLine().toString());
}
InputStream tablesContent = tablesRes.getEntity().getContent();
tables = new ObjectMapper().readTree(tablesContent).get("tables");
} catch (Exception e) {
LOG.error("Exception in loading collections", e);
} finally {
if (tablesRes.getEntity() != null) {
EntityUtils.consume(tablesRes.getEntity());
}
tablesRes.close();
}
return tables;
}
use of com.fasterxml.jackson.databind.JsonNode in project jmxtrans by jmxtrans.
the class JsonUtils method parseProcess.
/**
* Uses jackson to load json configuration from a File into a full object
* tree representation of that json.
*/
public JmxProcess parseProcess(File file) throws IOException {
JsonNode jsonNode = mapper.readTree(file);
JmxProcess jmx = mapper.treeToValue(jsonNode, JmxProcess.class);
jmx.setName(file.getName());
return jmx;
}
Aggregations