Skip to content

Source generator doesn't support [JsonExtensionData] #58273

@steveharter

Description

@steveharter

The [JsonExtensionData] attribute is not supported and silently fails.

Expect that the parser detects that attribute and passes that information\metadata to the serializer (best long-term), or we generate a design-time error (to help scope V6).

Repro:

using System.Text.Json;
using System.Text.Json.Serialization;
using Test;

POCO? poco = JsonSerializer.Deserialize("{\"Hello\":42}", MyContext.Default.POCO);
// Non-source gen works:
// POCO? poco = JsonSerializer.Deserialize<POCO>("{\"Hello\":42}");

// Throws since Overflow is null
Console.WriteLine(poco.Overflow["Hello"]);

namespace Test
{

    [JsonSerializable(typeof(POCO))]
    public partial class MyContext : JsonSerializerContext
    {
    }

    public partial class POCO
    {
        [JsonExtensionData]
        public Dictionary<string, JsonElement> Overflow { get; set; }
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions