Search in sources :

Example 41 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project hive by apache.

the class TestCodahaleMetrics method testFileReporting.

@Test
public void testFileReporting() throws Exception {
    int runs = 5;
    for (int i = 0; i < runs; i++) {
        MetricsFactory.getInstance().incrementCounter("count2");
    }
    byte[] jsonData = MetricsTestUtils.getFileData(jsonReportFile.getAbsolutePath(), 2000, 3);
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode rootNode = objectMapper.readTree(jsonData);
    JsonNode countersNode = rootNode.path("counters");
    JsonNode methodCounterNode = countersNode.path("count2");
    JsonNode countNode = methodCounterNode.path("count");
    Assert.assertEquals(countNode.asInt(), 5);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 42 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project zeppelin by apache.

the class SparkRInterpreter method interpret.

@Override
public InterpreterResult interpret(String lines, InterpreterContext interpreterContext) {
    SparkInterpreter sparkInterpreter = getSparkInterpreter();
    sparkInterpreter.populateSparkWebUrl(interpreterContext);
    String jobGroup = Utils.buildJobGroupId(interpreterContext);
    sparkInterpreter.getSparkContext().setJobGroup(jobGroup, "Zeppelin", false);
    String imageWidth = getProperty("zeppelin.R.image.width");
    String[] sl = lines.split("\n");
    if (sl[0].contains("{") && sl[0].contains("}")) {
        String jsonConfig = sl[0].substring(sl[0].indexOf("{"), sl[0].indexOf("}") + 1);
        ObjectMapper m = new ObjectMapper();
        try {
            JsonNode rootNode = m.readTree(jsonConfig);
            JsonNode imageWidthNode = rootNode.path("imageWidth");
            if (!imageWidthNode.isMissingNode())
                imageWidth = imageWidthNode.textValue();
        } catch (Exception e) {
            logger.warn("Can not parse json config: " + jsonConfig, e);
        } finally {
            lines = lines.replace(jsonConfig, "");
        }
    }
    String setJobGroup = "";
    // assign setJobGroup to dummy__, otherwise it would print NULL for this statement
    if (Utils.isSpark2()) {
        setJobGroup = "dummy__ <- setJobGroup(\"" + jobGroup + "\", \"zeppelin sparkR job group description\", TRUE)";
    } else if (getSparkInterpreter().getSparkVersion().newerThanEquals(SparkVersion.SPARK_1_5_0)) {
        setJobGroup = "dummy__ <- setJobGroup(sc, \"" + jobGroup + "\", \"zeppelin sparkR job group description\", TRUE)";
    }
    logger.debug("set JobGroup:" + setJobGroup);
    lines = setJobGroup + "\n" + lines;
    try {
        // render output with knitr
        if (useKnitr()) {
            zeppelinR.setInterpreterOutput(null);
            zeppelinR.set(".zcmd", "\n```{r " + renderOptions + "}\n" + lines + "\n```");
            zeppelinR.eval(".zres <- knit2html(text=.zcmd)");
            String html = zeppelinR.getS0(".zres");
            RDisplay rDisplay = render(html, imageWidth);
            return new InterpreterResult(rDisplay.code(), rDisplay.type(), rDisplay.content());
        } else {
            // alternatively, stream the output (without knitr)
            zeppelinR.setInterpreterOutput(interpreterContext.out);
            zeppelinR.eval(lines);
            return new InterpreterResult(InterpreterResult.Code.SUCCESS, "");
        }
    } catch (Exception e) {
        logger.error("Exception while connecting to R", e);
        return new InterpreterResult(InterpreterResult.Code.ERROR, e.getMessage());
    } finally {
        try {
        } catch (Exception e) {
        // Do nothing...
        }
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Example 43 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project cas by apereo.

the class RegisteredServiceJsonSerializer method initializeObjectMapper.

/**
     * Mixins are added to the object mapper in order to
     * ignore certain method signatures from serialization
     * that are otherwise treated as getters. Each mixin
     * implements the appropriate interface as a private
     * dummy class and is annotated with JsonIgnore elements
     * throughout. This helps us catch errors at compile-time
     * when the interface changes.
     *
     * @return the prepped object mapper.
     */
@Override
protected ObjectMapper initializeObjectMapper() {
    final ObjectMapper mapper = super.initializeObjectMapper();
    mapper.addHandler(new JasigRegisteredServiceDeserializationProblemHandler());
    return mapper;
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 44 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project cas by apereo.

the class AbstractJacksonBackedStringSerializer method initializeObjectMapper.

/**
     * Initialize object mapper.
     *
     * @return the object mapper
     */
protected ObjectMapper initializeObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper(getJsonFactory());
    configureObjectMapper(mapper);
    return mapper;
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 45 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project spring-boot-admin by codecentric.

the class ApplicationTest method test_json_format.

@Test
public void test_json_format() throws JsonProcessingException, IOException {
    ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
    Application app = Application.create("test").withHealthUrl("http://health").withServiceUrl("http://service").withManagementUrl("http://management").build();
    DocumentContext json = JsonPath.parse(objectMapper.writeValueAsString(app));
    assertThat((String) json.read("$.name")).isEqualTo("test");
    assertThat((String) json.read("$.serviceUrl")).isEqualTo("http://service");
    assertThat((String) json.read("$.managementUrl")).isEqualTo("http://management");
    assertThat((String) json.read("$.healthUrl")).isEqualTo("http://health");
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) Application(de.codecentric.boot.admin.client.registration.Application) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1523 Test (org.junit.Test)608 JsonNode (com.fasterxml.jackson.databind.JsonNode)217 IOException (java.io.IOException)191 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)172 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 Map (java.util.Map)122 HashMap (java.util.HashMap)111 ArrayList (java.util.ArrayList)71 File (java.io.File)56 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)53 JCodeModel (com.sun.codemodel.JCodeModel)52 InputStream (java.io.InputStream)50 JPackage (com.sun.codemodel.JPackage)44 List (java.util.List)42 JsonException (jmri.server.json.JsonException)41 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)39 JType (com.sun.codemodel.JType)38 Test (org.testng.annotations.Test)36 JsonFactory (com.fasterxml.jackson.core.JsonFactory)34