{"record":{"id":"09bad3a4f37922fb","repo":"elsa-workflows/elsa-core","slug":"expected-number-or-string","errorCode":null,"errorMessage":"Expected number or string.","messagePattern":"Expected number or string\\.","errorType":"validation","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Common/Converters/BigIntegerJsonConverter.cs","lineNumber":24,"sourceCode":"\n/// <summary>\n/// Converts big integers to and from JSON strings.\n/// </summary>\npublic class BigIntegerJsonConverter : JsonConverter<BigInteger>\n{\n    /// <inheritdoc />\n    public override BigInteger Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        if (reader.TokenType == JsonTokenType.Number)\n            return reader.GetInt64();\n\n        if (reader.TokenType == JsonTokenType.String)\n        {\n            var value = reader.GetString()!;\n            return long.Parse(value);\n        }\n\n        throw new JsonException(\"Expected number or string.\");\n    }\n\n    /// <inheritdoc />\n    public override void Write(Utf8JsonWriter writer, BigInteger value, JsonSerializerOptions options)\n    {\n        // Write the Big Integer as a JSON number.\n        writer.WriteNumberValue((long)value);\n    }\n}","sourceCodeStart":6,"sourceCodeEnd":33,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Common/Converters/BigIntegerJsonConverter.cs#L6-L33","documentation":"BigIntegerJsonConverter.Read deserializes a JSON token into a BigInteger, accepting only JSON numbers and strings parseable as long. Any other token type (true, false, null, object, array, etc.) causes a JsonException with the message 'Expected number or string.'","triggerScenarios":"Deserializing JSON where a field bound to BigInteger holds a non-numeric, non-string token — e.g. true/false/null, a nested object, or an array.","commonSituations":"API responses returning null for a numeric field; payload shape changes upstream; wiring the converter onto a bool or object property by mistake.","solutions":["Fix the JSON payload so the field is a number or a numeric string.","Make the property nullable or use JsonIgnoreCondition so nulls bypass the converter.","Use a custom converter override (or Read handling JsonTokenType.Null) if null must be accepted.","Verify the converter is only applied to properties that are actually numeric."],"exampleFix":"// before\n{\"count\": null}\n// after\n{\"count\": 42}","handlingStrategy":"validation","validationCode":"if (token.Type is not (JsonTokenType.Number or JsonTokenType.String))\n    throw new JsonException($\"Expected number or string for BigInteger, got {token.Type}.\");","typeGuard":"bool IsBigIntegerToken(JsonTokenType t) => t is JsonTokenType.Number or JsonTokenType.String;","tryCatchPattern":"try { var value = JsonSerializer.Deserialize<BigInteger>(json, options); }\ncatch (JsonException ex) { log.LogWarning(ex, \"Invalid BigInteger payload\"); value = BigInteger.Zero; }","preventionTips":["Contract-test payloads against the converter's accepted token types.","Handle JsonTokenType.Null explicitly if nullable semantics are needed.","Keep converter applicability limited to numeric properties."],"tags":["json","deserialization","system-text-json"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}