Skip to content

Commit 9ffed42

Browse files
committed
Changed the data contract for the models to use NewtonSoft serializer. Fixes microsoftgraph/msgraph-sdk-dotnet#28. Test called UpdateUser covers this scenario https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/mainer/functionComposable/tests/Microsoft.Graph.Test/Requests/Functional/UsersTests.cs
1 parent ae8abf2 commit 9ffed42

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Templates/CSharp/Model/ComplexType.cs.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var isMethodResponse = complex.LongDescriptionContains("methodResponse");
1616
var classType = complex.IsAbstract ? "abstract partial class" : "partial class";
1717

1818
var attributeStringBuilder = new StringBuilder();
19-
attributeStringBuilder.Append("[DataContract]");
19+
attributeStringBuilder.Append("[JsonObject(MemberSerialization = MemberSerialization.OptIn)]");
2020

2121
// We only want to add the derived type converter to the concrete class at the top of the inheritance hierarchy
2222
if (!complex.IsAbstract && complex.Derived != null && (complex.Base == null || complex.Base.IsAbstract))
@@ -51,7 +51,7 @@ namespace <#=complex.Namespace.GetNamespaceName()#>
5151
? property.Name.Substring(property.Name.IndexOf('.') + 1).ToCheckedCase()
5252
: property.Name.ToCheckedCase().GetSanitizedPropertyName();
5353

54-
var attributeDefinition = string.Format("[DataMember(Name = \"{0}\", EmitDefaultValue = false, IsRequired = false)]", property.Name);
54+
var attributeDefinition = string.Format("[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = \"{0}\", Required = Required.Default)]", property.Name);
5555

5656
if (property.IsTypeNullable() || property.IsCollection)
5757
{

Templates/CSharp/Model/EntityType.cs.tt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (entity.Base != null)
1414
}
1515

1616
var attributeStringBuilder = new StringBuilder();
17-
attributeStringBuilder.Append("[DataContract]");
17+
attributeStringBuilder.Append("[JsonObject(MemberSerialization = MemberSerialization.OptIn)]");
1818

1919
// We only want to add the derived type converter to the classes at the top of the inheritance hierarchy
2020
if (entity.Derived != null && entity.Base == null)
@@ -61,7 +61,7 @@ namespace <#=entity.Namespace.GetNamespaceName()#>
6161
var propertyName = property.Name.ToCheckedCase();
6262
var propertyCollectionPage = property.IsReference() ? string.Concat(entityName, propertyName, "CollectionWithReferencesPage") : string.Concat(entityName, propertyName, "CollectionPage");
6363

64-
var attributeDefinition = string.Format("[DataMember(Name = \"{0}\", EmitDefaultValue = false, IsRequired = false)]", property.Name);
64+
var attributeDefinition = string.Format("[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = \"{0}\", Required = Required.Default)]", property.Name);
6565

6666
if (property.IsCollection())
6767
{
@@ -109,7 +109,7 @@ namespace <#=entity.Namespace.GetNamespaceName()#>
109109
/// <summary>
110110
/// Gets or sets @odata.type.
111111
/// </summary>
112-
[DataMember(Name = "@odata.type", EmitDefaultValue = false, IsRequired = false)]
112+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "@odata.type", Required = Required.Default)]
113113
public string ODataType { get; set; }
114114

115115
/// <summary>

0 commit comments

Comments
 (0)