Skip to content

Source generator doesn't support [JsonExtensionData] #58273

Closed

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; }
    }
}

Activity

  1. added this to the 6.0.0 milestone on Aug 27, 2021
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Aug 27, 2021
  3. removed
    untriagedNew issue has not been triaged by the area owner
    on Aug 27, 2021
  4. self-assigned this
    on Sep 2, 2021
  5. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Sep 9, 2021
  6. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Sep 11, 2021
  7. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Sep 13, 2021
  8. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Sep 14, 2021
  9. ghost locked as resolved and limited conversation to collaborators on Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions