{"record":{"id":"6c72eef8ff2d651f","repo":"elsa-workflows/elsa-core","slug":"failed-to-parse-jsondocument-obsoleteconnectionjsonconverter","errorCode":null,"errorMessage":"Failed to parse JsonDocument","messagePattern":"Failed to parse JsonDocument","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Workflows.Core/Activities/Flowchart/Serialization/ObsoleteConnectionJsonConverter.cs","lineNumber":28,"sourceCode":"[Obsolete(\"Use ConnectionJsonConverter instead.\")]\npublic class ObsoleteConnectionJsonConverter : JsonConverter<ObsoleteConnection>\n{\n    private readonly IDictionary<string, IActivity> _activities;\n\n    /// <inheritdoc />\n    public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(ObsoleteConnection);\n\n    /// <inheritdoc />\n    public ObsoleteConnectionJsonConverter(IDictionary<string, IActivity> activities)\n    {\n        _activities = activities;\n    }\n\n    /// <inheritdoc />\n    public override ObsoleteConnection Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        if (!JsonDocument.TryParseValue(ref reader, out var doc))\n            throw new JsonException(\"Failed to parse JsonDocument\");\n\n        var sourceId = doc.RootElement.GetProperty(\"source\").GetString()!;\n        var targetId = doc.RootElement.GetProperty(\"target\").GetString()!;\n        var sourcePort = doc.RootElement.GetProperty(\"sourcePort\").GetString()!;\n        var targetPort = doc.RootElement.GetProperty(\"targetPort\").GetString()!;\n\n        var source = _activities.TryGetValue(sourceId, out var s) ? s : null!;\n        var target = _activities.TryGetValue(targetId, out var t) ? t : null!;\n\n        return new ObsoleteConnection(source, target, sourcePort, targetPort);\n    }\n\n    /// <inheritdoc />\n    public override void Write(Utf8JsonWriter writer, ObsoleteConnection value, JsonSerializerOptions options)\n    {\n        var (activity, target, sourcePort, targetPort) = value;\n\n        var model = new","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Serialization/ObsoleteConnectionJsonConverter.cs#L10-L46","documentation":"Thrown in ObsoleteConnectionJsonConverter.Read when the legacy connection JSON cannot be parsed into a JsonDocument. This converter handles the obsolete flat Connection format (source/target/sourcePort/targetPort strings), so the error indicates corrupt or non-object JSON in a legacy payload.","triggerScenarios":"Deserializing legacy workflow definitions whose connection JSON is malformed — truncated, wrong token type, or not a JSON object.","commonSituations":"Migrating old Elsa 2.x workflow definitions from storage where the JSON was corrupted; legacy export files edited by hand; partial reads of definition blobs.","solutions":["Validate the legacy JSON with JsonDocument.Parse before deserialization to find the corrupt element.","Verify the source storage (file/DB) is not truncating the definition JSON.","Confirm the legacy connection is an object: {\"source\":\"a\",\"target\":\"b\",\"sourcePort\":\"...\",\"targetPort\":\"...\"}.","If migrating, convert legacy definitions to the current format first, then deserialize."],"exampleFix":"// before\nvar conn = JsonSerializer.Deserialize<ObsoleteConnection>(legacyJson); // throws on malformed json\n// after\nusing var doc = JsonDocument.Parse(legacyJson); // pre-validate\nvar conn = JsonSerializer.Deserialize<ObsoleteConnection>(legacyJson);","handlingStrategy":"try-catch","validationCode":"using var doc = JsonDocument.Parse(legacyJson); // pre-validate before ObsoleteConnection deserialization","typeGuard":"static bool CanParseJson(string json) { try { using var _ = JsonDocument.Parse(json); return true; } catch (JsonException) { return false; } }","tryCatchPattern":"try { var conn = JsonSerializer.Deserialize<ObsoleteConnection>(legacyJson); }\ncatch (JsonException ex)\n{\n    logger.LogError(ex, \"Malformed legacy connection JSON during migration: {Message}\", ex.Message);\n}","preventionTips":["Snapshot and checksum legacy definition blobs before migration.","Validate all legacy JSON before running migration tooling.","Fix storage layers (file reads, DB queries) that may return partial payloads."],"tags":["json","serialization","legacy","deserialization"],"backgroundTag":"json-parse-error","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"}