Skip to content

Commit

Permalink
add fallback for primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean committed Feb 26, 2024
1 parent b26964f commit 99af9e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public static T FromExtensionOrDefault<T>(IAsyncApiExtension extension)
/// <returns><see cref="{T}" />.</returns>
public T GetValue<T>()
{
if (this.node is JsonValue)
{
return this.node.GetValue<T>();
}

return JsonSerializer.Deserialize<T>(this.node.ToJsonString());
}

Expand Down
2 changes: 1 addition & 1 deletion test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void GetValue_ReturnsCorrectConversions()
// Assert
Assert.AreEqual("string", a.GetValue<string>());
Assert.AreEqual(1, b.GetValue<int>());
Assert.AreEqual(1.1, c.GetValue<decimal>());
Assert.AreEqual(1.1, c.GetValue<double>());
Assert.AreEqual(true, d.GetValue<bool>());
Assert.NotNull(e.GetValue<MyType>());
Assert.IsNotEmpty(f.GetValue<List<string>>());
Expand Down

0 comments on commit 99af9e4

Please sign in to comment.