Description
This is a follow up to this comment:
Is there a plan to support [DataContract]
, [DataMember]
and friends?
Today this is a way to define how types should serialize/deserialize (e.g. the field name) in a way that doesn't bring a dependency to any serialization library to the project using it.
The current JsonNamingPolicy
takes a string only so there's no way to inspect the member's attributes. So it seems so far there's no way to support annotations (.NET Attributes) and as such no way to define the serialized name except from the original property name.
Motivation
System.Runtime.Serialization
is part of .NET Standard and it allows us to annotate members of a class in a way to hint a serialization library what name to use and whether to include it or not if the value is null
.
This is valuable because it allows us to have NuGet packages that don't depend on a serialization library directly.
Ensuring that a serialized version of a type matches a certain protocol could be done by means of tests only. This way we can make sure more than one library would be supported (like Newtonsoft.Json
and DataContractSerializer
at this point.