-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[System.Text.Json] Why does converters seem to not provide the name to serialize to? #36761
Comments
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
The scenario here may be addressed with work in #36785. |
@layomia Can the behavior of |
If there are multiple JSON properties, then you are writing out a JSON object, not a simple value like in the sample above. In that case, yes the property names are typically hard-coded in the converter since the serializer does not expose them yet. However, it is possible to use reflection in the converter and check for the As @layomia mentioned #36785 should address this scenario by providing a list of the serializable properties, which will have the JSON property name available from any |
I believe this has been addressed by #63686. |
So I got some code to a converter. After looking further I noticed I used the wrong value writers in the Write method due to the fact that the ones that needs the name to serialize to is missing the actual name. Also realized the ones that are used in this code is for json arrays.
While the code at this state uses it once at the moment, What if I needed to use the converter and type on a few things. I would sure hate to hard code what the name to write the value to and then it being wrong. That is why I think somehow the Write method could possible get whatever name marked with the
JsonPropertyName
attribute and then use that string value from that attribute as means to properly write the value without hard coding anything into the converter.The text was updated successfully, but these errors were encountered: