private void write(FieldPath fieldPath, Collection<FieldPathUpdate> fieldPathUpdates, JsonGenerator generator) throws IOException { generator.writeObjectFieldStart(fieldPath.toString()); for (FieldPathUpdate update : fieldPathUpdates) { if (writeArithmeticFieldPathUpdate(update, generator)) continue; generator.writeFieldName(update.getUpdateType().name().toLowerCase()); if (update instanceof AssignFieldPathUpdate) { AssignFieldPathUpdate assignUp = (AssignFieldPathUpdate) update; if (assignUp.getExpression() != null) { throw new RuntimeException("Unable to parse expression: " + assignUp.getExpression()); } else { assignUp.getNewValue().serialize(null, this); } } else if (update instanceof AddFieldPathUpdate) { ((AddFieldPathUpdate) update).getNewValues().serialize(null, this); } else if (update instanceof RemoveFieldPathUpdate) { generator.writeNumber(0); } else { throw new RuntimeException("Unsupported fieldpath operation: " + update.getClass().getName()); } } generator.writeEndObject(); }
@Override public String toString() { return "Assign: " + super.toString() + " : " + (isArithmetic() ? getExpression() : getNewValue().toString()); }