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

Bug: Public Fields not showing up when using System.Text.Json #1680

Open
brandonryan opened this issue Mar 7, 2024 · 0 comments
Open

Bug: Public Fields not showing up when using System.Text.Json #1680

brandonryan opened this issue Mar 7, 2024 · 0 comments

Comments

@brandonryan
Copy link

brandonryan commented Mar 7, 2024

Public fields aren't being generated in the output schema when SerializerOptions.IncludeFields = true.

Reproduction:
https://dotnetfiddle.net/amyqcs

Assuming it has something to do with SystemTextJsonReflectionService?
I think I narrowed it down to this line:

if (accessorInfo.MemberInfo.DeclaringType != contextualType.Type ||
    (accessorInfo.MemberInfo is FieldInfo fieldInfo && (fieldInfo.IsPrivate || fieldInfo.IsStatic || !fieldInfo.IsDefined(typeof(DataMemberAttribute)))))
{
    continue;
}

I would expect it to not require the DataMemberAttribute if IncludeFields is set. Exiting too early.

I did notice there were no tests for this specific thing in System.Text.Json Tests so I think it just fell through the cracks.

@brandonryan brandonryan changed the title public Fields not showing up when using System.Text.Json Bug: Public Fields not showing up when using System.Text.Json Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant