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

When an interface inherits an interface, System.Text.Json.JsonSerializer.Serialize only encodes the properties of the current interface into the json #48768

Closed
vsfeedback opened this issue Feb 25, 2021 · 6 comments
Assignees
Labels
area-System.Text.Json untriaged New issue has not been triaged by the area owner

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


The interface inherits the interface, and there should be content in the interface at the next level. Now System.Text.Json.JsonSerializer.Serialize encodes a string that contains only data for this level of interface, not the data for the interface's parent interface.
So I'm inglying back and hoping to get help.


Original Comments

Feedback Bot on 2/23/2021, 00:07 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Feb 25, 2021
@ghost
Copy link

ghost commented Feb 25, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details

This issue has been moved from a ticket on Developer Community.


The interface inherits the interface, and there should be content in the interface at the next level. Now System.Text.Json.JsonSerializer.Serialize encodes a string that contains only data for this level of interface, not the data for the interface's parent interface.
So I'm inglying back and hoping to get help.


Original Comments

Feedback Bot on 2/23/2021, 00:07 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

Author: vsfeedback
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@huoyaoyuan
Copy link
Member

Should be by design - System.Text.Json uses variable/member type instead of object type, unless the variable type is object.

@centreboard
Copy link
Contributor

centreboard commented Feb 25, 2021

In this example I would expect serialising as IFooBar to serialise both A and B, while it only serialises B in 5.0.3

using System;
using System.Text.Json;

var fooBar = new FooBar{A="Foo", B="Bar"};

Console.WriteLine(JsonSerializer.Serialize(fooBar, typeof(FooBar)));
Console.WriteLine(JsonSerializer.Serialize(fooBar, typeof(IFooBar)));
Console.WriteLine(JsonSerializer.Serialize(fooBar, typeof(Foo)));
Console.WriteLine(JsonSerializer.Serialize(fooBar, typeof(IFoo)));


interface IFoo
{
    string A {get;set;}
}

interface IFooBar: IFoo
{
    string B {get;set;}
}

class Foo: IFoo {
    public string A {get;set;}
}

class FooBar: Foo, IFooBar
{
    public string B {get;set;}
}

{"B":"Bar","A":"Foo"}
{"B":"Bar"}
{"A":"Foo"}
{"A":"Foo"}

@ShuiFan0
Copy link

In this example I would expect serialising as IFooBar to serialise both A and B?

using System;
using System.Text.Json;

var fooBar = new FooBar{A="Foo", B="Bar"};

Console.WriteLine(JsonSerializer.Serialize(fooBar, typeof(FooBar)));
Console.WriteLine(JsonSerializer.Serialize(fooBar, typeof(IFooBar)));
Console.WriteLine(JsonSerializer.Serialize(fooBar, typeof(Foo)));
Console.WriteLine(JsonSerializer.Serialize(fooBar, typeof(IFoo)));


interface IFoo
{
    string A {get;set;}
}

interface IFooBar: IFoo
{
    string B {get;set;}
}

class Foo: IFoo {
    public string A {get;set;}
}

class FooBar: Foo, IFooBar
{
    public string B {get;set;}
}

{"B":"Bar","A":"Foo"}
{"B":"Bar"}
{"A":"Foo"}
{"A":"Foo"}

Yes,this I would expect

@huoyaoyuan
Copy link
Member

Well, in this case your expectation is reasonable. I don't know about the design here.

@eiriktsarpalis
Copy link
Member

Duplicate of #41749.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

6 participants