From 9eb27ece859c17cc0017a6fc5309888f23c8a464 Mon Sep 17 00:00:00 2001 From: Sam Xu Date: Fri, 11 Feb 2022 12:05:09 -0800 Subject: [PATCH 1/2] Create type annotation only with type name --- .../Formatter/Serialization/ODataPrimitiveSerializer.cs | 5 ++++- .../Microsoft.Test.E2E.AspNet.OData/OpenType/TypedTest.cs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.OData.Shared/Formatter/Serialization/ODataPrimitiveSerializer.cs b/src/Microsoft.AspNet.OData.Shared/Formatter/Serialization/ODataPrimitiveSerializer.cs index 9c20c83c00..290656dabd 100644 --- a/src/Microsoft.AspNet.OData.Shared/Formatter/Serialization/ODataPrimitiveSerializer.cs +++ b/src/Microsoft.AspNet.OData.Shared/Formatter/Serialization/ODataPrimitiveSerializer.cs @@ -125,7 +125,10 @@ internal static void AddTypeNameAnnotationAsNeeded(ODataPrimitiveValue primitive typeName = primitiveType.FullName(); } - primitive.TypeAnnotation = new ODataTypeAnnotation(typeName); + if (typeName != null) + { + primitive.TypeAnnotation = new ODataTypeAnnotation(typeName); + } } internal static ODataPrimitiveValue CreatePrimitive(object value, IEdmPrimitiveTypeReference primitiveType, diff --git a/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/OpenType/TypedTest.cs b/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/OpenType/TypedTest.cs index e48a66b535..c73f553175 100644 --- a/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/OpenType/TypedTest.cs +++ b/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/OpenType/TypedTest.cs @@ -436,7 +436,7 @@ public async Task PatchOpenComplexTypeProperty() response = await Client.SendAsync(request); Assert.Equal(HttpStatusCode.OK, response.StatusCode); content = await response.Content.ReadAsObject(); - Assert.Equal(6, content.Count); // @odata.context + 3 declared properties + 1 dynamic properties + 1 new dynamic properties + Assert.Equal(7, content.Count); // @odata.context + 3 declared properties + 2 dynamic properties + 1 new dynamic properties Assert.Equal("NewCity", content["City"]); // updated Assert.Equal("1 Microsoft Way", content["Street"]); Assert.Equal("US", content["CountryCode"]); @@ -529,7 +529,7 @@ public async Task PutOpenComplexTypeProperty() response = await Client.SendAsync(request); Assert.Equal(HttpStatusCode.OK, response.StatusCode); content = await response.Content.ReadAsObject(); - Assert.Equal(5, content.Count); // @odata.context + 3 declared properties + 1 new dynamic properties + Assert.Equal(6, content.Count); // @odata.context + 3 declared properties + 2 new dynamic properties Assert.Equal("NewCity", content["City"]); // updated Assert.Equal("NewStreet", content["Street"]); // updated Assert.Equal("US", content["CountryCode"]); From c5a482c8aeeb81dba3dfd5fb58f509f6da0df957 Mon Sep 17 00:00:00 2001 From: Sam Xu Date: Fri, 11 Feb 2022 14:38:18 -0800 Subject: [PATCH 2/2] Fix the failing test and fix the build warning --- src/Microsoft.AspNet.OData.Shared/DeltaOfTStructuralType.cs | 2 +- .../JsonLight/JsonLightDeserializationAndSerializationTests.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.OData.Shared/DeltaOfTStructuralType.cs b/src/Microsoft.AspNet.OData.Shared/DeltaOfTStructuralType.cs index 7e558dad74..c92d4fc5d8 100644 --- a/src/Microsoft.AspNet.OData.Shared/DeltaOfTStructuralType.cs +++ b/src/Microsoft.AspNet.OData.Shared/DeltaOfTStructuralType.cs @@ -643,7 +643,7 @@ private void InitializeProperties(IEnumerable updatableProperties) } } - private bool IsIgnoredProperty(bool isTypeDataContract, PropertyInfo propertyInfo) + private static bool IsIgnoredProperty(bool isTypeDataContract, PropertyInfo propertyInfo) { //This is for Ignoring the property that matches below criteria //1. Its marked as NotMapped diff --git a/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/Formatter/JsonLight/JsonLightDeserializationAndSerializationTests.cs b/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/Formatter/JsonLight/JsonLightDeserializationAndSerializationTests.cs index e3cc932272..a55cc79a20 100644 --- a/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/Formatter/JsonLight/JsonLightDeserializationAndSerializationTests.cs +++ b/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/Formatter/JsonLight/JsonLightDeserializationAndSerializationTests.cs @@ -195,6 +195,7 @@ public async Task SerializationTests() @"""string3"":""}t@xt{""," + @"""string4"":""[t@xt'',,][']other::]mo}{retext""," + @"""number10"":10," + + @"""number10point5@odata.type"":""#decimal""," + @"""number10point5"":10.5," + @"""number10e25"":1E+26," + @"""boolean_true"":true," +