Search in sources :

Example 91 with JsonNode

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)));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PropertyDescriptor(java.beans.PropertyDescriptor) JsonNode(com.fasterxml.jackson.databind.JsonNode) Method(java.lang.reflect.Method)

Example 92 with JsonNode

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));
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 93 with JsonNode

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);
            }
        }
    }
}
Also used : Schema(com.linkedin.pinot.common.data.Schema) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 94 with JsonNode

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;
}
Also used : InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Example 95 with JsonNode

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;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JmxProcess(com.googlecode.jmxtrans.model.JmxProcess)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1055 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)275 Test (org.junit.Test)267 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)165 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)125 IOException (java.io.IOException)124 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)97 HashMap (java.util.HashMap)78 ArrayList (java.util.ArrayList)75 HttpGet (org.apache.http.client.methods.HttpGet)69 JsonException (jmri.server.json.JsonException)66 Deployment (org.activiti.engine.test.Deployment)66 InputStream (java.io.InputStream)64 StringEntity (org.apache.http.entity.StringEntity)54 ByteArrayInputStream (java.io.ByteArrayInputStream)53 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)49 Map (java.util.Map)45 Task (org.activiti.engine.task.Task)41 HttpPost (org.apache.http.client.methods.HttpPost)39 Tree (org.apache.jackrabbit.oak.api.Tree)30