use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project buck by facebook.
the class JsonMatcher method matchesSafely.
@Override
protected boolean matchesSafely(String actualJson, Description description) {
try {
JsonFactory factory = MAPPER.getFactory();
JsonParser jsonParser = factory.createParser(String.format(expectedJson));
JsonNode expectedObject = MAPPER.readTree(jsonParser);
jsonParser = factory.createParser(actualJson);
JsonNode actualObject = MAPPER.readTree(jsonParser);
if (!matchJsonObjects("/", expectedObject, actualObject, description)) {
description.appendText(String.format(" in <%s>", actualJson));
return false;
}
} catch (IOException e) {
description.appendText(String.format("could not parse the following into a json object: <%s>", actualJson));
return false;
}
return true;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory 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.JsonFactory 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.JsonFactory in project nifi by apache.
the class DataPacketDto method getDataPacketStream.
public static Stream<DataPacket> getDataPacketStream(InputStream inputStream) throws IOException {
JsonParser jsonParser = new JsonFactory().createParser(inputStream);
if (jsonParser.nextToken() != JsonToken.START_ARRAY) {
throw new IOException("Expecting start array token to begin object array.");
}
jsonParser.setCodec(new ObjectMapper());
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<DataPacket>() {
DataPacket next = getNext();
@Override
public boolean hasNext() {
return next != null;
}
@Override
public DataPacket next() {
DataPacket next = this.next;
this.next = getNext();
return next;
}
DataPacket getNext() throws RuntimeException {
try {
if (jsonParser.nextToken() == JsonToken.END_ARRAY) {
return null;
}
DataPacketDto dataPacketDto = jsonParser.readValueAs(DATA_PACKET_DTO_TYPE_REFERENCE);
return dataPacketDto.toDataPacket();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}, Spliterator.ORDERED), false);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory 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();
}
Aggregations