@Override public void write(final OutputStream output) throws IOException, WebApplicationException { final Iterator<E> iterator = entities.iterator(); try { final JsonGenerator generator = mapper.getFactory().createGenerator(output); generator.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); generator.writeStartArray(); while (iterator.hasNext()) { final E entity = iterator.next(); final J asJson = toJson.apply(entity); if (asJson != null) { generator.writeObject(asJson); } } generator.writeEndArray(); generator.close(); } finally { // In case the client goes away (IOException), make sure to close the underlying DB connection entities.close(); } } };
@Override public void write(final OutputStream output) throws IOException, WebApplicationException { try { final JsonGenerator generator = mapper.getFactory().createGenerator(output); generator.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); generator.writeStartObject(); while (iterator.hasNext()) { final Tag tag = iterator.next(); final UUID accountId = tag.getObjectId(); try { invoiceUserApi.triggerInvoiceGeneration(accountId, clock.getUTCToday(), callContext); generator.writeStringField(accountId.toString(), OK); } catch (final InvoiceApiException e) { if (e.getCode() != ErrorCode.INVOICE_NOTHING_TO_DO.getCode()) { log.warn("Unable to trigger invoice generation for accountId='{}'", accountId); } generator.writeStringField(accountId.toString(), ErrorCode.fromCode(e.getCode()).toString()); } } generator.writeEndObject(); generator.close(); } finally { // In case the client goes away (IOException), make sure to close the underlying DB connection tags.close(); } } };