Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add GUID-from-string support
  • Loading branch information
Turnerj committed Dec 14, 2019
commit d4f08f571f267c7827ce38770d7421918fd49366
5 changes: 5 additions & 0 deletions Source/Schema.NET/ValuesJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ private static bool TryProcessTokenAsType(JsonReader reader, Type targetType, ou
success = Uri.TryCreate(valueString, UriKind.Absolute, out var localResult);
result = localResult;
}
else if (targetType == typeof(Guid))
{
success = Guid.TryParse(valueString, out var localResult);
result = localResult;
}
}
else if (tokenType == JsonToken.Integer || tokenType == JsonToken.Float)
{
Expand Down
8 changes: 8 additions & 0 deletions Tests/Schema.NET.Test/ValuesJsonConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ public void ReadJson_Values_SingleValue_BooleanAsString()
Assert.True(result.Value2.First());
}

[Fact]
public void ReadJson_Values_SingleValue_GuidAsString()
{
var json = "{\"Property\":\"13ec75b3-250c-48a2-8bd0-dfee62852bd4\"}";
var result = this.DeserializeObject<Values<string, Guid>>(json);
Assert.Equal(new Guid("13ec75b3-250c-48a2-8bd0-dfee62852bd4"), result.Value2.First());
}

[Fact]
public void ReadJson_Values_SingleValue_NullablePrimitiveAsString()
{
Expand Down