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();
}
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();
}
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());
}
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();
}
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);
}
}
Aggregations