use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project open-kilda by telstra.
the class TopologyPrinter method toJson.
/**
* @return A json representation of the topology. Intended for printing only.
*/
public static final String toJson(ITopology topo, boolean pretty) throws IOException {
ObjectMapper mapper = new ObjectMapper();
if (pretty)
mapper.enable(SerializationFeature.INDENT_OUTPUT);
StringWriter sw = new StringWriter();
JsonFactory f = mapper.getFactory();
try (JsonGenerator g = f.createGenerator(sw)) {
g.writeStartObject();
// use TreeSet to sort the list
g.writeObjectField("switches", new TreeSet<String>(topo.getSwitches().keySet()));
g.writeObjectField("links", new TreeSet<String>(topo.getLinks().keySet()));
g.writeEndObject();
}
return sw.toString();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project nifi by apache.
the class RedisStateMapJsonSerDe method serialize.
@Override
public byte[] serialize(final RedisStateMap stateMap) throws IOException {
if (stateMap == null) {
return null;
}
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
final JsonGenerator jsonGenerator = jsonFactory.createGenerator(out);
jsonGenerator.writeStartObject();
jsonGenerator.writeNumberField(FIELD_VERSION, stateMap.getVersion());
jsonGenerator.writeNumberField(FIELD_ENCODING, stateMap.getEncodingVersion());
jsonGenerator.writeObjectFieldStart(FIELD_STATE_VALUES);
for (Map.Entry<String, String> entry : stateMap.toMap().entrySet()) {
jsonGenerator.writeStringField(entry.getKey(), entry.getValue());
}
jsonGenerator.writeEndObject();
jsonGenerator.writeEndObject();
jsonGenerator.flush();
return out.toByteArray();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project nifi by apache.
the class SiteToSiteReceiver method receiveFiles.
public TransactionCompletion receiveFiles() throws IOException {
Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE);
JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output);
jsonGenerator.writeStartArray();
DataPacket dataPacket;
while ((dataPacket = transaction.receive()) != null) {
jsonGenerator.writeStartObject();
jsonGenerator.writeFieldName("attributes");
jsonGenerator.writeStartObject();
Map<String, String> attributes = dataPacket.getAttributes();
if (attributes != null) {
for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) {
jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue());
}
}
jsonGenerator.writeEndObject();
InputStream data = dataPacket.getData();
if (data != null) {
jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data));
}
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
jsonGenerator.close();
transaction.confirm();
return transaction.complete();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project CFLint by cflint.
the class TestCFLintConfig method test2.
@Test
public void test2() throws IOException {
StringWriter writer = new StringWriter();
JsonFactory jsonF = new JsonFactory();
JsonGenerator jg = jsonF.createGenerator(writer);
jg.writeStartArray();
jg.writeEndArray();
jg.close();
writer.close();
System.out.println(writer);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project geode by apache.
the class PdxToJSON method getJSON.
public String getJSON() {
JsonFactory jf = new JsonFactory();
// OutputStream os = new ByteArrayOutputStream();
HeapDataOutputStream hdos = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
try {
JsonGenerator jg = jf.createJsonGenerator(hdos, JsonEncoding.UTF8);
enableDisableJSONGeneratorFeature(jg);
getJSONString(jg, m_pdxInstance);
jg.close();
return new String(hdos.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
} finally {
hdos.close();
}
}
Aggregations