use of com.yahoo.document.json.JsonWriter in project vespa by vespa-engine.
the class OperationHandlerImpl method get.
@Override
public Optional<String> get(RestUri restUri, Optional<String> fieldSet) throws RestApiException {
SyncSession syncSession = syncSessions.alloc();
setRoute(syncSession, Optional.empty());
try {
DocumentId id = new DocumentId(restUri.generateFullId());
final Document document = syncSession.get(id, fieldSet.orElse(restUri.getDocumentType() + ":[document]"), DocumentProtocol.Priority.NORMAL_1);
if (document == null) {
return Optional.empty();
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JsonWriter jsonWriter = new JsonWriter(outputStream);
jsonWriter.write(document);
return Optional.of(outputStream.toString(StandardCharsets.UTF_8.name()));
} catch (Exception e) {
throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.UNSPECIFIED));
} finally {
syncSessions.free(syncSession);
}
}
Aggregations