MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException, WebApplicationException {
try {
EntityWriter writer = EntityRegistry.findWriter(object.getEntity().getClass());
// Multiple repositories: ok to use public repo since only non-repository-specific things are needed
ObjectNode json = writer.toJson(object.getEntity(), object.getWriteOptions(),
repositoryMgr.getDefaultRepository());
JsonFormat.serialize(json, new CloseShieldOutputStream(entityStream));
} catch (Throwable e) {
// We catch every throwable, since otherwise no one does it and we will not have any trace
// of Errors that happened.