this.properties = properties == null ? EntityProviderWriteProperties.serviceRoot(null).build() : properties;
}
public void append(final Writer writer, final EntityInfoAggregator entityInfo, final List<Map<String, Object>> data,
final boolean isRootElement) throws EntityProviderException {
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
TombstoneCallback callback = getTombstoneCallback();
try {
jsonStreamWriter.beginObject();
if (isRootElement) {
jsonStreamWriter.name(FormatJson.D)
.beginObject();
}
if (properties.getInlineCountType() == InlineCount.ALLPAGES) {
final int inlineCount = properties.getInlineCount() == null ? 0 : properties.getInlineCount();
jsonStreamWriter.namedStringValueRaw(FormatJson.COUNT, String.valueOf(inlineCount)).separator();
}
jsonStreamWriter.name(FormatJson.RESULTS)
.beginArray();
JsonEntryEntityProducer entryProducer = new JsonEntryEntityProducer(properties);
boolean first = true;
for (final Map<String, Object> entryData : data) {
if (first) {
first = false;
} else {
jsonStreamWriter.separator();
}
entryProducer.append(writer, entityInfo, entryData, false);
}
if (callback != null) {
JsonDeletedEntryEntityProducer deletedEntryProducer = new JsonDeletedEntryEntityProducer(properties);
TombstoneCallbackResult callbackResult = callback.getTombstoneCallbackResult();
List<Map<String, Object>> deletedEntries = callbackResult.getDeletedEntriesData();
if (deletedEntries != null) {
deletedEntryProducer.append(writer, entityInfo, deletedEntries);
}
}
jsonStreamWriter.endArray();
appendNextLink(jsonStreamWriter);
appendDeltaLink(callback, jsonStreamWriter);
if (isRootElement) {
jsonStreamWriter.endObject();
}
jsonStreamWriter.endObject();
} catch (final IOException e) {
throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
.getSimpleName()), e);
}
}