anchor.diff:    Iterable<TypeHelper> get _allHelpers =>
         [_typeHelpers, _coreHelpers].expand((e) => e);
   
  +  String _serializeField(FieldElement field, {String accessOverride}) {
  +    accessOverride ??= field.name;
  +    try {
  +      return _serialize(field.type, accessOverride, _nullable(field));
  +    } on UnsupportedTypeError {
  +      throw new InvalidGenerationSourceError(
  +          'Could not generate `toJson` code for '
  +          '`${friendlyNameForElement(field)}`.',
  +          todo: 'Make sure all of the types are serializable.');
  +    }
  +  }
  +
     /// [expression] may be just the name of the field or it may an expression
     /// representing the serialization of a value.
     String _serialize(DartType targetType, String expression, bool nullable) =>
  
positive.code:     return buffer.toString();
    }
  
    void _writeToJsonWithNullChecks(
        StringBuffer buffer, Iterable<FieldElement> fields, bool includeIfNull) {
      buffer.writeln('{');
  
      buffer.writeln('var $toJsonMapVarName = <String, dynamic>{');
  
negative.code:     var directWrite = true;
  
      for (var field in fields) {
        var safeFieldAccess = field.name;
        var safeJsonKeyString = _safeNameAccess(field);
  
        // If `fieldName` collides with one of the local helpers, prefix
        // access with `this.`.
        if (safeFieldAccess == toJsonMapVarName ||
            safeFieldAccess == toJsonMapHelperName) {
          safeFieldAccess = 'this.$safeFieldAccess';
        }
  
        if (_includeIfNull(field, classIncludeIfNull)) {
          if (directWrite) {
            buffer.writeln('$safeJsonKeyString : '
                '${_serializeField(field, accessOverride:  safeFieldAccess)},');
          } else {
            buffer.writeln('$toJsonMapVarName[$safeJsonKeyString] = '
                '${_serializeField(field, accessOverride:  safeFieldAccess)};');
          }
        } else {
          if (directWrite) {
            // close the still-open map literal
            buffer.writeln('};');
            buffer.writeln();
  
            // write the helper to be used by all following null-excluding
            // fields
            buffer.writeln('''
  void $toJsonMapHelperName(String key, dynamic value) {
    if (value != null) {
      $toJsonMapVarName[key] = value;
    }
  }''');
            directWrite = false;
          }
          buffer.writeln('$toJsonMapHelperName($safeJsonKeyString, '
              '${_serializeField(field, accessOverride:  safeFieldAccess)});');
        }
      }
  
  