Search in sources :

Example 41 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project languagetool by languagetool-org.

the class RuleMatchesAsJsonSerializer method ruleMatchesToJson.

/**
   * @param incompleteResults use true to indicate that results are incomplete (e.g. due to a timeout) - a 'warnings'
   *                          section will be added to the JSON
   * @since 3.7
   */
@Experimental
public String ruleMatchesToJson(List<RuleMatch> matches, String text, int contextSize, Language lang, boolean incompleteResults) {
    ContextTools contextTools = new ContextTools();
    contextTools.setEscapeHtml(false);
    contextTools.setContextSize(contextSize);
    contextTools.setErrorMarkerStart(START_MARKER);
    contextTools.setErrorMarkerEnd("");
    StringWriter sw = new StringWriter();
    try {
        try (JsonGenerator g = factory.createGenerator(sw)) {
            g.writeStartObject();
            writeSoftwareSection(g);
            writeWarningsSection(g, incompleteResults);
            writeLanguageSection(g, lang);
            writeMatchesSection(g, matches, text, contextTools);
            g.writeEndObject();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) Experimental(org.languagetool.Experimental)

Example 42 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project spring-framework by spring-projects.

the class AbstractJackson2View method writeContent.

/**
	 * Write the actual JSON content to the stream.
	 * @param stream the output stream to use
	 * @param object the value to be rendered, as returned from {@link #filterModel}
	 * @throws IOException if writing failed
	 */
protected void writeContent(OutputStream stream, Object object) throws IOException {
    JsonGenerator generator = this.objectMapper.getFactory().createGenerator(stream, this.encoding);
    writePrefix(generator, object);
    Class<?> serializationView = null;
    FilterProvider filters = null;
    Object value = object;
    if (value instanceof MappingJacksonValue) {
        MappingJacksonValue container = (MappingJacksonValue) value;
        value = container.getValue();
        serializationView = container.getSerializationView();
        filters = container.getFilters();
    }
    if (serializationView != null) {
        this.objectMapper.writerWithView(serializationView).writeValue(generator, value);
    } else if (filters != null) {
        this.objectMapper.writer(filters).writeValue(generator, value);
    } else {
        this.objectMapper.writeValue(generator, value);
    }
    writeSuffix(generator, object);
    generator.flush();
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider)

Example 43 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project flink by apache.

the class CurrentJobsOverviewHandlerTest method testJsonGeneration.

@Test
public void testJsonGeneration() throws Exception {
    AccessExecutionGraph originalJob = ArchivedJobGenerationUtils.getTestJob();
    JobDetails expectedDetails = WebMonitorUtils.createDetailsForJob(originalJob);
    StringWriter writer = new StringWriter();
    try (JsonGenerator gen = ArchivedJobGenerationUtils.jacksonFactory.createGenerator(writer)) {
        CurrentJobsOverviewHandler.writeJobDetailOverviewAsJson(expectedDetails, gen, 0);
    }
    compareJobOverview(expectedDetails, writer.toString());
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) AccessExecutionGraph(org.apache.flink.runtime.executiongraph.AccessExecutionGraph) JobDetails(org.apache.flink.runtime.messages.webmonitor.JobDetails) Test(org.junit.Test)

Example 44 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project hadoop by apache.

the class Configuration method dumpConfiguration.

/**
   *  Writes out all properties and their attributes (final and resource) to
   *  the given {@link Writer}, the format of the output would be,
   *
   *  <pre>
   *  { "properties" :
   *      [ { key : "key1",
   *          value : "value1",
   *          isFinal : "key1.isFinal",
   *          resource : "key1.resource" },
   *        { key : "key2",
   *          value : "value2",
   *          isFinal : "ke2.isFinal",
   *          resource : "key2.resource" }
   *       ]
   *   }
   *  </pre>
   *
   *  It does not output the properties of the configuration object which
   *  is loaded from an input stream.
   *  <p>
   *
   * @param config the configuration
   * @param out the Writer to write to
   * @throws IOException
   */
public static void dumpConfiguration(Configuration config, Writer out) throws IOException {
    JsonFactory dumpFactory = new JsonFactory();
    JsonGenerator dumpGenerator = dumpFactory.createGenerator(out);
    dumpGenerator.writeStartObject();
    dumpGenerator.writeFieldName("properties");
    dumpGenerator.writeStartArray();
    dumpGenerator.flush();
    synchronized (config) {
        for (Map.Entry<Object, Object> item : config.getProps().entrySet()) {
            appendJSONProperty(dumpGenerator, config, item.getKey().toString());
        }
    }
    dumpGenerator.writeEndArray();
    dumpGenerator.writeEndObject();
    dumpGenerator.flush();
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) UnmodifiableMap(org.apache.commons.collections.map.UnmodifiableMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Example 45 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project presto by prestodb.

the class JsonEventClient method postEvent.

@Override
public <T> void postEvent(T event) throws IOException {
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        JsonGenerator generator = factory.createGenerator(buffer, JsonEncoding.UTF8);
        serializer.serialize(event, generator);
        out.println(buffer.toString().trim());
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)711 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)257 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)257 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)257 IOException (java.io.IOException)170 StringWriter (java.io.StringWriter)145 JsonFactory (com.fasterxml.jackson.core.JsonFactory)101 ByteArrayOutputStream (java.io.ByteArrayOutputStream)66 Map (java.util.Map)57 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 HashMap (java.util.HashMap)41 Test (org.junit.Test)30 File (java.io.File)27 ArrayList (java.util.ArrayList)26 OutputStream (java.io.OutputStream)25 Writer (java.io.Writer)22 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)21 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)20 FileOutputStream (java.io.FileOutputStream)19