XINCGer/Unity3DTraining · error · NotImplementedException

Haven't worked out what to do for null yet

Error message

Haven't worked out what to do for null yet

What it means

ParseSingleValue handles string, number, and other concrete JSON tokens, but the JSON null token for a single (non-repeated, non-Any) field value is not implemented in this Google.Protobuf version, so it throws a NotImplementedException. This is an explicit feature gap rather than an input-validation failure.

Solutions

  1. Preprocess the JSON to strip properties whose value is null before calling Parse (remove keys rather than emitting null).
  2. Omit the field entirely — in proto3, an absent field equals the default value.
  3. Upgrade Google.Protobuf: newer versions implement the canonical null-as-default behavior for some field kinds; verify against your version's release notes.
  4. Catch NotImplementedException around Parse as a stopgap and log it as a payload-shape issue.

Example fix

// before
{"userName": null, "userId": 5}

// after: omit the null field
{"userId": 5}
Defensive patterns

Strategy: validation

Validate before calling

// Remove keys whose value is null before parsing (null means 'use default' in proto3)
function stripNulls(obj) {
  if (Array.isArray(obj)) return obj.map(stripNulls);
  if (obj && typeof obj === 'object') {
    return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== null).map(([k, v]) => [k, stripNulls(v)]));
  }
  return obj;
}

Try / catch

try { var msg = JsonParser.Default.Parse<T>(json); }
catch (NotImplementedException) { /* payload contains null for a single field: strip nulls and retry, or upgrade library */ }

Prevention

When it happens

Trigger: Calling JsonParser.Parse with JSON that assigns null to a single field, e.g. {"optionalString": null} or {"myMessageField": null}, reaching the Null case of the token switch.

Common situations: Backend/frontend JSON where null signals 'no value' (per canonical protobuf JSON spec, null should mean 'use default' but older parser versions didn't implement it); serializers that always emit keys with null values; version mismatch between the spec you read and the Google.Protobuf version in use.

Related errors


AI-assisted analysis of XINCGer/Unity3DTraining@016f98412e (2026-09-12). Data as JSON: /api/errors/0d5cb955b46feea6. Report an issue: GitHub.

Appendix: source

Thrown at NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs:363

            switch (token.Type)
            {
                case JsonToken.TokenType.True:
                case JsonToken.TokenType.False:
                    if (fieldType == FieldType.Bool)
                    {
                        return token.Type == JsonToken.TokenType.True;
                    }
                    // Fall through to "we don't support this type for this case"; could duplicate the behaviour of the default
                    // case instead, but this way we'd only need to change one place.
                    goto default;
                case JsonToken.TokenType.StringValue:
                    return ParseSingleStringValue(field, token.StringValue);
                // Note: not passing the number value itself here, as we may end up storing the string value in the token too.
                case JsonToken.TokenType.Number:
                    return ParseSingleNumberValue(field, token);
                case JsonToken.TokenType.Null:
                    throw new NotImplementedException("Haven't worked out what to do for null yet");
                default:
                    throw new InvalidProtocolBufferException("Unsupported JSON token type " + token.Type + " for field type " + fieldType);
            }
        }

        /// <summary>
        /// Parses <paramref name="json"/> into a new message.
        /// </summary>
        /// <typeparam name="T">The type of message to create.</typeparam>
        /// <param name="json">The JSON to parse.</param>
        /// <exception cref="InvalidJsonException">The JSON does not comply with RFC 7159</exception>
        /// <exception cref="InvalidProtocolBufferException">The JSON does not represent a Protocol Buffers message correctly</exception>
        public T Parse<T>(string json) where T : IMessage, new()
        {
            ProtoPreconditions.CheckNotNull(json, "json");
            return Parse<T>(new StringReader(json));
        }

View on GitHub (pinned to 016f98412e)