Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Validates multidimensional collections scenarios using UntypedNode. #221

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions Microsoft.Kiota.Serialization.Json.Tests/JsonParseNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class JsonParseNodeTests
" }\r\n" +
" ],\r\n" +
" \"detail\": null,\r\n" +
" \"table\": [[1,2,3],[4,5,6],[7,8,9]],\r\n" +
" \"extra\": {\r\n" +
" \"createdDateTime\":\"2024-01-15T00:00:00\\u002B00:00\"\r\n" +
" }\r\n" +
Expand Down Expand Up @@ -273,6 +274,18 @@ public void GetEntityWithUntypedNodesFromJson()
Assert.Null(entity.Detail);
var extra = entity.AdditionalData["extra"];
Assert.NotNull(extra);
Assert.NotNull(entity.Table);
var table = (UntypedArray)entity.Table;// the table is a collection
foreach(var value in table.GetValue())
{
var row = (UntypedArray)value;
Assert.NotNull(row);// The values are a nested collection
foreach(var item in row.GetValue())
{
var rowItem = (UntypedInteger)item;
Assert.NotNull(rowItem);// The values are a nested collection
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


using System;
using System.Collections.Generic;
using Microsoft.Kiota.Abstractions.Serialization;
Expand All @@ -14,6 +14,7 @@ public class UntypedTestEntity : IParsable, IAdditionalDataHolder
public UntypedNode Location { get; set; }
public UntypedNode Keywords { get; set; }
public UntypedNode Detail { get; set; }
public UntypedNode Table { get; set; }
public UntypedTestEntity()
{
AdditionalData = new Dictionary<string, object>();
Expand All @@ -27,7 +28,8 @@ public IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
{ "title", node => Title = node.GetStringValue() },
{ "location", node => Location = node.GetObjectValue(UntypedNode.CreateFromDiscriminatorValue) },
{ "keywords", node => Keywords = node.GetObjectValue(UntypedNode.CreateFromDiscriminatorValue) },
{ "detail", node => Detail = node.GetObjectValue(UntypedNode.CreateFromDiscriminatorValue) }
{ "detail", node => Detail = node.GetObjectValue(UntypedNode.CreateFromDiscriminatorValue) },
{ "table", node => Table = node.GetObjectValue(UntypedNode.CreateFromDiscriminatorValue) },
};
}
public void Serialize(ISerializationWriter writer)
Expand All @@ -37,6 +39,7 @@ public void Serialize(ISerializationWriter writer)
writer.WriteObjectValue("location", Location);
writer.WriteObjectValue("keywords", Keywords);
writer.WriteObjectValue("detail", Detail);
writer.WriteObjectValue("table", Table);
writer.WriteAdditionalData(AdditionalData);
}
public static UntypedTestEntity CreateFromDiscriminatorValue(IParseNode parseNode)
Expand Down
Loading