Newtonsoft.Json - ignore DataContractAttribute

i is of type

class Foo { public string Name { get; set; } } 

and I can quickly serialize it using the JsonConvert.SerializeObject() method (without user settings). But if I decorate the class definition with [DataContract] , the Name property is not serialized.

Is there a way to serialize a DataContract Foo type WITHOUT decorating it with additional attributes of Newtonsoft.Json ?

+4
source share
1 answer

Try annotating a property with the DataMember attribute :

 [DataContract] class Foo { [DataMember] public string Name { get; set; } } 
+5
source

Source: https://habr.com/ru/post/1387222/


All Articles