Skip to content

Commit d44463f

Browse files
author
Caitlin Bales (MSFT)
committed
Replace DataMember with JsonProperty
1 parent 529e478 commit d44463f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Templates/CSharp/Model/MethodRequestBody.cs.tt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ var requestBody = entityName + method.Name.Substring(method.Name.IndexOf('.') +
1313
// and violate the spec.
1414
System.Diagnostics.Debug.Assert(!method.Overloads.Any(), "Overload actions are not allowed in OData services");
1515

16+
var attributeStringBuilder = new StringBuilder();
17+
attributeStringBuilder.Append("[JsonObject(MemberSerialization = MemberSerialization.OptIn)]");
1618
#>
1719

1820
namespace <#=method.Namespace.GetNamespaceName()#>
1921
{
22+
using Newtonsoft.Json;
2023
using System;
2124
using System.Collections.Generic;
2225
using System.IO;
@@ -25,7 +28,7 @@ namespace <#=method.Namespace.GetNamespaceName()#>
2528
/// <summary>
2629
/// The type <#=requestBody#>.
2730
/// </summary>
28-
[DataContract]
31+
<#=attributeStringBuilder.ToString()#>
2932
public partial class <#=requestBody#>
3033
{
3134
<#
@@ -43,12 +46,13 @@ namespace <#=method.Namespace.GetNamespaceName()#>
4346
}
4447

4548
var paramName = param.Name.ToCheckedCase().GetSanitizedPropertyName();
49+
var attributeDefinition = string.Format("[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = \"{0}\", Required = Required.Default)]", param.Name);
4650
#>
4751

4852
/// <summary>
4953
/// Gets or sets <#=paramName#>.
5054
/// </summary>
51-
[DataMember(Name = "<#=param.Name#>", EmitDefaultValue = false, IsRequired = false)]
55+
<#=attributeDefinition#>
5256
public <#=paramTypeString#> <#=paramName#> { get; set; }
5357
<#
5458
}

0 commit comments

Comments
 (0)