Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonTypeInfoResolver doesn't populate inherited properties in interface hierarchy #77276

Closed
captainsafia opened this issue Oct 20, 2022 · 3 comments

Comments

@captainsafia
Copy link
Member

Description

Using the DefaultJsonTypeInfoResolver API to identify the properties for an interface in a type hierarchy does not populate inherited properties in JsonTypeInfo.Properties.

Reproduction Steps

using System.Text.Json;
using System.Text.Json.Serialization.Metadata;

GetPropertiesFromType(typeof(IBaseInterface));
GetPropertiesFromType(typeof(ISubInterface1));
GetPropertiesFromType(typeof(ISubInterface2));
GetPropertiesFromType(typeof(IMultiSubInterface));


static void GetPropertiesFromType(Type type)
{
    var typeInfoResolver = new DefaultJsonTypeInfoResolver();
    var jsonType = typeInfoResolver.GetTypeInfo(type, JsonSerializerOptions.Default);

    if (jsonType.Kind == JsonTypeInfoKind.Object)
    {
        Console.WriteLine(string.Join(", ", jsonType.Properties.Select(property => property.Name)));
    }
}

interface IBaseInterface
{
    string BaseProperty { get; set; }
}

interface ISubInterface1 : IBaseInterface
{
    int Property1 { get; set; }
}

interface ISubInterface2 : IBaseInterface
{
    int Property2 { get; set; }
}

interface IMultiSubInterface : ISubInterface1, ISubInterface2
{
    int Property3 { get; set; }
}

Expected behavior

$ dotnet run
BaseProperty
Property1, BaseProperty
Property2, BaseProperty
Property3, Property2, Property1, BaseProperty

Actual behavior

$ dotnet run
BaseProperty
Property1
Property2
Property3

Regression?

No response

Known Workarounds

No response

Configuration

dotnet --info
.NET SDK:
 Version:   7.0.100-rtm.22478.4
 Commit:    9624df5579

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.6
 OS Platform: Darwin
 RID:         osx.12-arm64
 Base Path:   /Users/captainsafia/.dotnet/sdk/7.0.100-rtm.22478.4/

Host:
  Version:      7.0.0-rtm.22476.12
  Architecture: arm64
  Commit:       915dc27235

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 20, 2022
@ghost
Copy link

ghost commented Oct 20, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Using the DefaultJsonTypeInfoResolver API to identify the properties for an interface in a type hierarchy does not populate inherited properties in JsonTypeInfo.Properties.

Reproduction Steps

using System.Text.Json;
using System.Text.Json.Serialization.Metadata;

GetPropertiesFromType(typeof(IBaseInterface));
GetPropertiesFromType(typeof(ISubInterface1));
GetPropertiesFromType(typeof(ISubInterface2));
GetPropertiesFromType(typeof(IMultiSubInterface));


static void GetPropertiesFromType(Type type)
{
    var typeInfoResolver = new DefaultJsonTypeInfoResolver();
    var jsonType = typeInfoResolver.GetTypeInfo(type, JsonSerializerOptions.Default);

    if (jsonType.Kind == JsonTypeInfoKind.Object)
    {
        Console.WriteLine(string.Join(", ", jsonType.Properties.Select(property => property.Name)));
    }
}

interface IBaseInterface
{
    string BaseProperty { get; set; }
}

interface ISubInterface1 : IBaseInterface
{
    int Property1 { get; set; }
}

interface ISubInterface2 : IBaseInterface
{
    int Property2 { get; set; }
}

interface IMultiSubInterface : ISubInterface1, ISubInterface2
{
    int Property3 { get; set; }
}

Expected behavior

$ dotnet run
BaseProperty
Property1, BaseProperty
Property2, BaseProperty
Property3, Property2, Property1, BaseProperty

Actual behavior

$ dotnet run
BaseProperty
Property1
Property2
Property3

Regression?

No response

Known Workarounds

No response

Configuration

dotnet --info
.NET SDK:
 Version:   7.0.100-rtm.22478.4
 Commit:    9624df5579

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.6
 OS Platform: Darwin
 RID:         osx.12-arm64
 Base Path:   /Users/captainsafia/.dotnet/sdk/7.0.100-rtm.22478.4/

Host:
  Version:      7.0.0-rtm.22476.12
  Architecture: arm64
  Commit:       915dc27235

Other information

No response

Author: captainsafia
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

@eiriktsarpalis
Copy link
Member

Duplicate of #41749. We were hoping to address this in .NET 7 but ran into design questions regarding handling of diamond ambiguities that arise in interface hierarchies.

@eiriktsarpalis
Copy link
Member

cc @krwq @layomia we should prioritize this fix given a partner team is impacted by the bug.

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Oct 20, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants