-
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.Serialization.JsonSerializer should respect DataMemberAttribute.Name #30009
Comments
Is there a particular reason why the new |
We have tens of thousand lines of code and would like to replace Newtonsoft.Json with the new functionality. |
+1 for sticking with an existing API. |
For example, if we build a Blazor app, and ofc we'd like to make JSON models shared between our server and client to keep them consistent, but on the client side (i.e. Blazor project), we can't use What's more, many existing projects now use I knew that now it's life after WCF, and we'd better not use these attributes introduced by WCF since it's nearly EoS. But we need attributes that could describe JSON models across so many JSON libs and runtime. |
there is currently no replacement for [DataMember(EmitDefaultValue)] in System.Text.Json. |
@ahsonkhan Can you explain why it is necessary to create a new attribute only for json serialization? What if I also need to serialize to other formats? Should I now decorate my type with additional attributes? Why not use the existing common attribute? |
@jjrdk, I agree. It seems logical to abstract the serialization decorations to allow for the serializing and deserializing in multiple formats (based on request Accept headers for example). |
Closing as duplicate - this falls under the ask to support types from System.Runtime.Serialization: https://github.com/dotnet/corefx/issues/38758. |
Should this be reopened as the conclusion of #29975 was to make individual issues for individual features, which this is. |
…ssues: 1. Lacks support for DataContract/DataMember attributes: dotnet/runtime#29975 dotnet/runtime#30009 2. Deserializes the primitive values as JsonElement instances.
Early-on during design of STJ in 3.0, it was decided not to support pre-existing attributes mainly because they would only be partially supported and it would be hit-and-miss meaning STJ would only support some of those in the first release and additional support added in future releases. This would cause endless confusion over what is and what is not supported. STJ can't just throw Also since STJ would need to explicitly look for those attributes, it would cause some slowdown during warm-up. Consider just the
Then there's also a few other attributes including So we went with a new explicit model that is intuitive (if it's not in the STJ namespace then it's not supported) that is high-performance with the thought we can add support for pre-existing attributes through an opt-in mode\flag of some sort or perhaps a pluggable metadata provider. These have not been implemented yet. Moving-forward, having a pluggable metadata provider along with an opt-in System.Runtime.Serialization "compat" implementation of that provider makes sense to me. Not sure if that has enough priority for 6.0, but it could be considered along with the feature to expose metadata and more flexible converters. |
The following code outputs
{"MyDataMember":"dataMember"}
, should be{"RENAMED":"dataMember"}
The text was updated successfully, but these errors were encountered: