From 8ef8b49ce26076b8992f1b5f1b2552e11e77ce74 Mon Sep 17 00:00:00 2001
From: Antonio Coelho <38294807+AntonioSCoelho@users.noreply.github.com>
Date: Wed, 24 Apr 2024 18:58:58 +0000
Subject: [PATCH 1/3] Parse empty strings as nullable Guid
---
.../JsonParseNodeTests.cs | 17 +++++++++++++++++
src/JsonParseNode.cs | 17 ++++++++++++++---
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/Microsoft.Kiota.Serialization.Json.Tests/JsonParseNodeTests.cs b/Microsoft.Kiota.Serialization.Json.Tests/JsonParseNodeTests.cs
index 76f2dc9..6d2c56a 100644
--- a/Microsoft.Kiota.Serialization.Json.Tests/JsonParseNodeTests.cs
+++ b/Microsoft.Kiota.Serialization.Json.Tests/JsonParseNodeTests.cs
@@ -220,6 +220,23 @@ public void ParseGuidWithoutConverter()
Assert.Equal(id, entity.Id);
}
+ [Fact]
+ public void ParseGuidEmptyString()
+ {
+ // Arrange
+ var json = $"{{\"id\": \"\"}}";
+ var serializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.General);
+ var serializationContext = new KiotaJsonSerializationContext(serializerOptions);
+ using var jsonDocument = JsonDocument.Parse(json);
+ var rootParseNode = new JsonParseNode(jsonDocument.RootElement, serializationContext);
+
+ // Act
+ var entity = rootParseNode.GetObjectValue(_ => new ConverterTestEntity());
+
+ // Assert
+ Assert.Null(entity.Id);
+ }
+
[Fact]
public void GetEntityWithUntypedNodesFromJson()
{
diff --git a/src/JsonParseNode.cs b/src/JsonParseNode.cs
index a64fd08..43cd50e 100644
--- a/src/JsonParseNode.cs
+++ b/src/JsonParseNode.cs
@@ -125,9 +125,20 @@ public JsonParseNode(JsonElement node, KiotaJsonSerializationContext jsonSeriali
/// Get the guid value from the json node
///
/// A guid value
- public Guid? GetGuidValue() => _jsonNode.ValueKind == JsonValueKind.String
- ? _jsonNode.Deserialize(_jsonSerializerContext.Guid)
- : null;
+ public Guid? GetGuidValue()
+ {
+ if(_jsonNode.ValueKind != JsonValueKind.String)
+ return null;
+
+ if(_jsonNode.TryGetGuid(out var guid))
+ return guid;
+
+ var guidStr = _jsonNode.GetString();
+ if(string.IsNullOrEmpty(guidStr))
+ return null;
+
+ return _jsonNode.Deserialize(_jsonSerializerContext.Guid);
+ }
///
/// Get the value from the json node
From 3affb019711d57da168d627f3026899e8ef9e6d1 Mon Sep 17 00:00:00 2001
From: Antonio Coelho <38294807+AntonioSCoelho@users.noreply.github.com>
Date: Wed, 24 Apr 2024 19:24:43 +0000
Subject: [PATCH 2/3] bump the version in the csproj. Added changelog.
---
CHANGELOG.md | 6 ++++++
src/Microsoft.Kiota.Serialization.Json.csproj | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 83d7095..87e8902 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [1.2.3] - 2024-04-25
+
+### Changed
+
+- Parse empty strings as nullable Guid
+
## [1.2.2] - 2024-04-19
### Changed
diff --git a/src/Microsoft.Kiota.Serialization.Json.csproj b/src/Microsoft.Kiota.Serialization.Json.csproj
index f552450..beffd07 100644
--- a/src/Microsoft.Kiota.Serialization.Json.csproj
+++ b/src/Microsoft.Kiota.Serialization.Json.csproj
@@ -15,7 +15,7 @@
https://aka.ms/kiota/docs
true
true
- 1.2.2
+ 1.2.3
true
true
From 7a612ecdaf0c5ea26181d948fdab67e5c9b49e19 Mon Sep 17 00:00:00 2001
From: Antonio Coelho <38294807+AntonioSCoelho@users.noreply.github.com>
Date: Wed, 24 Apr 2024 19:26:10 +0000
Subject: [PATCH 3/3] resolve sugestion
---
src/JsonParseNode.cs | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/JsonParseNode.cs b/src/JsonParseNode.cs
index 43cd50e..f91286e 100644
--- a/src/JsonParseNode.cs
+++ b/src/JsonParseNode.cs
@@ -133,8 +133,7 @@ public JsonParseNode(JsonElement node, KiotaJsonSerializationContext jsonSeriali
if(_jsonNode.TryGetGuid(out var guid))
return guid;
- var guidStr = _jsonNode.GetString();
- if(string.IsNullOrEmpty(guidStr))
+ if(string.IsNullOrEmpty(_jsonNode.GetString()))
return null;
return _jsonNode.Deserialize(_jsonSerializerContext.Guid);