diff --git a/Source/Common/ValuesJsonConverter.cs b/Source/Common/ValuesJsonConverter.cs index 66e5ed8a..1f5dac07 100644 --- a/Source/Common/ValuesJsonConverter.cs +++ b/Source/Common/ValuesJsonConverter.cs @@ -379,7 +379,7 @@ private static bool TryProcessTokenAsType(ref Utf8JsonReader reader, Type target } else if (targetType == typeof(Uri)) { - success = Uri.TryCreate(valueString, UriKind.Absolute, out var localResult); + success = Uri.TryCreate(valueString, UriKind.RelativeOrAbsolute, out var localResult); result = localResult; } else if (targetType == typeof(Guid)) diff --git a/Tests/Schema.NET.Test/ValuesJsonConverterTest.cs b/Tests/Schema.NET.Test/ValuesJsonConverterTest.cs index 7880e782..61103413 100644 --- a/Tests/Schema.NET.Test/ValuesJsonConverterTest.cs +++ b/Tests/Schema.NET.Test/ValuesJsonConverterTest.cs @@ -263,6 +263,14 @@ public void ReadJson_ParseValueToken_UriAsString() Assert.Equal(new Uri("https://schema.org/Thing"), result.Value2.First()); } + [Fact] + public void ReadJson_ParseValueToken_RelativeUriAsString() + { + var json = "{\"Property\":\"thing\"}"; + var result = DeserializeObject>(json); + Assert.Equal(new Uri("thing", UriKind.Relative), result.Value2.First()); + } + [Fact] public void ReadJson_Values_SingleValue_ThingInterface() { @@ -273,6 +281,7 @@ public void ReadJson_Values_SingleValue_ThingInterface() "\"@id\":\"https://example.com/book/1\"," + "\"name\":\"The Catcher in the Rye\"," + "\"url\":\"https://www.barnesandnoble.com/store/info/offer/JDSalinger\"," + + "\"image\":\"book1.jpg\"," + "\"author\":{" + "\"@type\":\"Person\"," + "\"name\":\"J.D. Salinger\"" + @@ -285,6 +294,7 @@ public void ReadJson_Values_SingleValue_ThingInterface() Assert.Equal(new Uri("https://example.com/book/1"), ((Book)actual).Id); Assert.Equal("The Catcher in the Rye", actual.Name); Assert.Equal(new Uri("https://www.barnesandnoble.com/store/info/offer/JDSalinger"), (Uri)actual.Url!); + Assert.Equal(new Uri("book1.jpg", UriKind.Relative), (Uri)actual.Image!); var author = Assert.Single(actual.Author.Value2); Assert.Equal("J.D. Salinger", author.Name); }