Search in sources :

Example 1 with MinimalPrettyPrinter

use of com.fasterxml.jackson.core.util.MinimalPrettyPrinter in project hadoop by apache.

the class TestLogInfo method writeDomainLeaveOpen.

private void writeDomainLeaveOpen(TimelineDomain domain, Path logPath) throws IOException {
    if (outStreamDomain == null) {
        outStreamDomain = PluginStoreTestUtils.createLogFile(logPath, fs);
    }
    // Write domain uses its own json generator to isolate from entity writers
    JsonGenerator jsonGeneratorLocal = new JsonFactory().createGenerator(outStreamDomain);
    jsonGeneratorLocal.setPrettyPrinter(new MinimalPrettyPrinter("\n"));
    objMapper.writeValue(jsonGeneratorLocal, domain);
    outStreamDomain.hflush();
}
Also used : MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 2 with MinimalPrettyPrinter

use of com.fasterxml.jackson.core.util.MinimalPrettyPrinter in project jackson-core by FasterXML.

the class TestPrettyPrinter method testSimpleDocWithMinimal.

@SuppressWarnings("resource")
public void testSimpleDocWithMinimal() throws Exception {
    StringWriter sw = new StringWriter();
    JsonGenerator gen = new JsonFactory().createGenerator(sw);
    // first with standard minimal
    gen.setPrettyPrinter(new MinimalPrettyPrinter());
    String docStr = _verifyPrettyPrinter(gen, sw);
    // which should have no linefeeds, tabs
    assertEquals(-1, docStr.indexOf('\n'));
    assertEquals(-1, docStr.indexOf('\t'));
    // And then with slightly customized variant
    gen = new JsonFactory().createGenerator(sw);
    gen.setPrettyPrinter(new MinimalPrettyPrinter() {

        @Override
        public // use TAB between array values
        void beforeArrayValues(JsonGenerator jg) throws IOException, JsonGenerationException {
            jg.writeRaw("\t");
        }
    });
    docStr = _verifyPrettyPrinter(gen, sw);
    assertEquals(-1, docStr.indexOf('\n'));
    assertTrue(docStr.indexOf('\t') >= 0);
    gen.close();
}
Also used : MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter)

Example 3 with MinimalPrettyPrinter

use of com.fasterxml.jackson.core.util.MinimalPrettyPrinter in project asterixdb by apache.

the class ResultState method toString.

@Override
public String toString() {
    try {
        ObjectMapper om = new ObjectMapper();
        ObjectNode on = om.createObjectNode();
        on.put("rspid", resultSetPartitionId.toString());
        on.put("async", asyncMode);
        on.put("eos", eos.get());
        on.put("failed", failed.get());
        on.put("fileRef", String.valueOf(fileRef));
        return om.writer(new MinimalPrettyPrinter()).writeValueAsString(on);
    } catch (JsonProcessingException e) {
        // NOSONAR
        return e.getMessage();
    }
}
Also used : MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with MinimalPrettyPrinter

use of com.fasterxml.jackson.core.util.MinimalPrettyPrinter in project hadoop by apache.

the class PluginStoreTestUtils method writeEntities.

/**
   * Write timeline entities to a file system
   * @param entities
   * @param logPath
   * @param fs
   * @throws IOException
   */
static void writeEntities(TimelineEntities entities, Path logPath, FileSystem fs) throws IOException {
    FSDataOutputStream outStream = createLogFile(logPath, fs);
    JsonGenerator jsonGenerator = new JsonFactory().createGenerator(outStream);
    jsonGenerator.setPrettyPrinter(new MinimalPrettyPrinter("\n"));
    ObjectMapper objMapper = createObjectMapper();
    for (TimelineEntity entity : entities.getEntities()) {
        objMapper.writeValue(jsonGenerator, entity);
    }
    outStream.close();
}
Also used : MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with MinimalPrettyPrinter

use of com.fasterxml.jackson.core.util.MinimalPrettyPrinter in project hadoop by apache.

the class TestLogInfo method writeEntitiesLeaveOpen.

// TestLogInfo needs to maintain opened hdfs files so we have to build our own
// write methods
private void writeEntitiesLeaveOpen(TimelineEntities entities, Path logPath) throws IOException {
    if (outStream == null) {
        outStream = PluginStoreTestUtils.createLogFile(logPath, fs);
        jsonGenerator = new JsonFactory().createGenerator(outStream);
        jsonGenerator.setPrettyPrinter(new MinimalPrettyPrinter("\n"));
    }
    for (TimelineEntity entity : entities.getEntities()) {
        objMapper.writeValue(jsonGenerator, entity);
    }
    outStream.hflush();
}
Also used : MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)

Aggregations

MinimalPrettyPrinter (com.fasterxml.jackson.core.util.MinimalPrettyPrinter)7 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 BasicJsonOutput (org.apache.drill.exec.vector.complex.fn.BasicJsonOutput)1 ExtendedJsonOutput (org.apache.drill.exec.vector.complex.fn.ExtendedJsonOutput)1 Configuration (org.apache.hadoop.conf.Configuration)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 Stringify (org.hjson.Stringify)1