Search in sources :

Example 1 with CircleStreamBuffer

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();
}
Also used : CircleStreamBuffer(org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) SerializerException(org.apache.olingo.server.api.serializer.SerializerException)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 IOException (java.io.IOException)1 SerializerException (org.apache.olingo.server.api.serializer.SerializerException)1 CircleStreamBuffer (org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer)1