use of org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer in project teiid by teiid.
the class TeiidODataJsonSerializer method complexCollection.
public SerializerResult complexCollection(final ServiceMetadata metadata, final List<List<ComplexReturnType>> result, final ContextURL contextURL, final URI nextLink) throws SerializerException {
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
json.writeStartObject();
if (contextURL != null) {
json.writeStringField(Constants.JSON_CONTEXT, ContextURLBuilder.create(contextURL).toASCIIString());
}
json.writeFieldName(Constants.VALUE);
json.writeStartArray();
for (List<ComplexReturnType> ct : result) {
json.writeStartObject();
for (final ComplexReturnType type : ct) {
if (!type.isExpand()) {
json.writeStringField(type.getName() + Constants.JSON_NAVIGATION_LINK, type.getEntity().getId().toASCIIString());
} else {
json.writeFieldName(type.getName());
writeEntity(metadata, type.getEdmEntityType(), type.getEntity(), null, null, null, null, false, null, type.getName(), json);
}
}
json.writeEndObject();
}
json.writeEndArray();
if (nextLink != null) {
json.writeStringField(Constants.JSON_NEXT_LINK, nextLink.toASCIIString());
}
json.close();
} catch (final IOException e) {
throw new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
}
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
Aggregations