@Override public void write(DocumentUpdate update) { wrapIOException(() -> { generator.writeStartObject(); generator.writeStringField("update", update.getId().toString()); if (update.getCondition().isPresent()) { generator.writeStringField("condition", update.getCondition().getSelection()); } Optional<Boolean> createIfNotExistent = update.getOptionalCreateIfNonExistent(); if (createIfNotExistent.isPresent()) { generator.writeBooleanField("create", createIfNotExistent.get()); } generator.writeObjectFieldStart("fields"); for (FieldUpdate up : update.fieldUpdates()) { up.serialize(this); } update.fieldPathUpdates().stream() .collect(Collectors.groupingBy(FieldPathUpdate::getFieldPath)) .forEach((fieldPath, fieldPathUpdates) -> wrapIOException(() -> write(fieldPath, fieldPathUpdates, generator))); generator.writeEndObject(); generator.writeEndObject(); generator.flush(); }); }
@Override public void write(DocumentUpdate update) { update.getId().serialize(this); update.getDocumentType().serialize(this); putInt(null, update.fieldUpdates().size()); for (FieldUpdate up : update.fieldUpdates()) { up.serialize(this); } DocumentUpdateFlags flags = new DocumentUpdateFlags(); flags.setCreateIfNonExistent(update.getCreateIfNonExistent()); putInt(null, flags.injectInto(update.fieldPathUpdates().size())); for (FieldPathUpdate up : update.fieldPathUpdates()) { up.serialize(this); } }