use of nl.nn.adapterframework.stream.document.INodeBuilder 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);
}
}
use of nl.nn.adapterframework.stream.document.INodeBuilder in project iaf by ibissource.
the class StrictJsonDocumentWriter method writeRaw.
@Override
public void writeRaw(final String value) {
notNull("value", value);
checkState(State.VALUE);
try {
try (INodeBuilder nodeBuilder = context.contextType == JsonContextType.ARRAY ? ((IArrayBuilder) stack.peek()).addElement() : (INodeBuilder) stack.pop()) {
nodeBuilder.setValue(value);
}
} catch (SAXException e) {
throwBSONException(e);
}
setNextState();
}
Aggregations