-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
Closed
Copy link
Labels
Priority:2Work that is important, but not critical for the releaseWork that is important, but not critical for the releasearea-System.Text.Jsonpartner-impactThis issue impacts a partner who needs to be kept updatedThis issue impacts a partner who needs to be kept updated
Milestone
Description
I would expect that inherited properties of interfaces would be serialized similar to (abstract) base classes.
Given:
public interface IBase
{
string BaseProperty { get; set; }
}
public interface IDerived : IBase
{
string DerivedProperty { get; set; }
}
public class Derived : IDerived
{
public string BaseProperty { get; set; }
public string DerivedProperty { get; set; }
}
public class Data
{
public IDerived Derived { get; set; }
}
Data data = new Data
{
Derived = new Derived
{
BaseProperty = "B",
DerivedProperty = "D"
}
};
string json = JsonSerializer.Serialize(data);
Where the json string is missing the BaseProperty:
{"Derived":{"DerivedProperty":"D"}}
replacing the interface with an abstract class results in:
{"Derived":{"DerivedProperty":"D","BaseProperty":"B"}}
public abstract class IBase
{
public string BaseProperty { get; set; }
}
public abstract class IDerived : IBase
{
public string DerivedProperty { get; set; }
}
public class Derived : IDerived
{
}
public class Data
{
public IDerived Derived { get; set; }
}
cinderblockgames, dancojocaru2000, SvenEV, thirstyape, SvenEV-bakerhughes and 1 more
Metadata
Metadata
Assignees
Labels
Priority:2Work that is important, but not critical for the releaseWork that is important, but not critical for the releasearea-System.Text.Jsonpartner-impactThis issue impacts a partner who needs to be kept updatedThis issue impacts a partner who needs to be kept updated