diff --git a/src/Microsoft.OData.Core/JsonLight/ODataJsonLightDeserializer.cs b/src/Microsoft.OData.Core/JsonLight/ODataJsonLightDeserializer.cs index 42e70829fc..1a98daae7f 100644 --- a/src/Microsoft.OData.Core/JsonLight/ODataJsonLightDeserializer.cs +++ b/src/Microsoft.OData.Core/JsonLight/ODataJsonLightDeserializer.cs @@ -270,10 +270,12 @@ internal void ReadPayloadStart( { // If the Base uri string is http://odata.org/test // The MetadataDocumentUri will be http://odata.org/test/$metadata - // If the contextUriAnnotation value is Customers(1)/Name + // If the contextUriAnnotation value is Customers(1)/Name or $metadata#Customers(1)/Name // The generated context uri will be http://odata.org/test/$metadata#Customers(1)/Name ODataUri oDataUri = new ODataUri() { ServiceRoot = this.BaseUri }; - contextUriAnnotationValue = oDataUri.MetadataDocumentUri.ToString() + ODataConstants.ContextUriFragmentIndicator + contextUriAnnotationValue; + contextUriAnnotationValue = contextUriAnnotationValue.StartsWith("$metadata#", StringComparison.OrdinalIgnoreCase) + ? this.BaseUri + contextUriAnnotationValue + : oDataUri.MetadataDocumentUri.ToString() + ODataConstants.ContextUriFragmentIndicator + contextUriAnnotationValue; } ODataJsonLightContextUriParseResult parseResult = null; diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/JsonLight/ODataJsonLightDeserializerTests.cs b/test/FunctionalTests/Microsoft.OData.Core.Tests/JsonLight/ODataJsonLightDeserializerTests.cs index af281a5379..ef140e1f14 100644 --- a/test/FunctionalTests/Microsoft.OData.Core.Tests/JsonLight/ODataJsonLightDeserializerTests.cs +++ b/test/FunctionalTests/Microsoft.OData.Core.Tests/JsonLight/ODataJsonLightDeserializerTests.cs @@ -873,6 +873,12 @@ public void TopLevelPropertyShouldReadContextUriAsRelativeUri() Assert.NotNull(property); Assert.Equal("http://odata.org/test/$metadata#Customers(1)/Name", deserializer.ContextUriParseResult.ContextUri.ToString()); + + deserializer = new ODataJsonLightPropertyAndValueDeserializer(this.CreateJsonLightInputContext("{\"@odata.context\":\"$metadata#Customers(1)/Name\",\"value\":\"Joe\"}", model)); + property = deserializer.ReadTopLevelProperty(primitiveTypeRef); + + Assert.NotNull(property); + Assert.Equal("http://odata.org/test/$metadata#Customers(1)/Name", deserializer.ContextUriParseResult.ContextUri.ToString()); }