use of nl.nn.adapterframework.stream.document.ArrayBuilder in project iaf by ibissource.
the class MongoDbSender method renderResult.
protected void renderResult(FindIterable<Document> findResults, MessageOutputStream target) throws StreamingException {
try {
if (isCountOnly()) {
try (Writer writer = target.asWriter()) {
int count = 0;
for (Document doc : findResults) {
count++;
}
writer.write(Integer.toString(count));
}
return;
}
try (ArrayBuilder builder = DocumentBuilderFactory.startArrayDocument(getOutputFormat(), "FindManyResult", "item", target)) {
JsonWriterSettings writerSettings = JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).build();
Encoder<Document> encoder = new DocumentCodec();
for (Document doc : findResults) {
try (INodeBuilder element = builder.addElement()) {
JsonDocumentWriter jsonWriter = new JsonDocumentWriter(element, writerSettings);
encoder.encode(jsonWriter, doc, EncoderContext.builder().build());
}
}
}
} catch (Exception e) {
throw new StreamingException("Could not render collection", e);
}
}
Aggregations