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

Json property order in System.Text.Json #43415

Closed
kotx opened this issue Oct 14, 2020 · 2 comments
Closed

Json property order in System.Text.Json #43415

kotx opened this issue Oct 14, 2020 · 2 comments

Comments

@kotx
Copy link

kotx commented Oct 14, 2020

Users should be able to specify the order of a json property during serialization.
It is possible to specify order by changing the order of the properties in the code. However, it is not possible to do this in inherited classes.

Example

// FooView.cs
public class FooView : BaseView
{
    public string Foo { get; set; }
}
// BaseView.cs
public class BaseView
{
    public bool Success { get; set; }
}

FooView's properties will always be placed before BaseView's upon serialization.

{
    "Foo": "bar",
    "Success": true
}

Implementation

Newtonsoft.Json does it like this:

[JsonProperty(Order = -2)]
public string Foo { get; set; }

An idea for System.Text.Json could be to use the DataMemberAttribute instead of creating its own attribute.

@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Oct 14, 2020
@am11
Copy link
Member

am11 commented Oct 15, 2020

Duplicate of #728.

@kotx kotx closed this as completed Oct 15, 2020
@kotx
Copy link
Author

kotx commented Oct 15, 2020

Closed in favor of #728.

@layomia layomia removed the untriaged New issue has not been triaged by the area owner label Oct 21, 2020
@layomia layomia added this to the 6.0.0 milestone Oct 21, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
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

5 participants