Skip to content

Commit

Permalink
Validates handling of multi dimensional arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Omondi committed May 6, 2024
1 parent 5ec927c commit 70ad2fc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
26 changes: 26 additions & 0 deletions internal/untyped_test_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type UntypedTestEntity struct {
location absser.UntypedNodeable
keywords absser.UntypedNodeable
detail absser.UntypedNodeable
table absser.UntypedNodeable
}

type TestUntypedTestEntityable interface {
Expand All @@ -26,6 +27,8 @@ type TestUntypedTestEntityable interface {
SetKeywords(value absser.UntypedNodeable)
GetDetail() absser.UntypedNodeable
SetDetail(value absser.UntypedNodeable)
GetTable() absser.UntypedNodeable
SetTable(value absser.UntypedNodeable)
}

func NewUntypedTestEntity() *UntypedTestEntity {
Expand Down Expand Up @@ -80,6 +83,13 @@ func (e *UntypedTestEntity) SetDetail(value absser.UntypedNodeable) {
e.detail = value
}

func (e *UntypedTestEntity) GetTable() absser.UntypedNodeable {
return e.table
}
func (e *UntypedTestEntity) SetTable(value absser.UntypedNodeable) {
e.table = value
}

func (e *UntypedTestEntity) GetFieldDeserializers() map[string]func(absser.ParseNode) error {
res := make(map[string]func(absser.ParseNode) error)
res["id"] = func(n absser.ParseNode) error {
Expand Down Expand Up @@ -132,6 +142,16 @@ func (e *UntypedTestEntity) GetFieldDeserializers() map[string]func(absser.Parse
}
return nil
}
res["table"] = func(n absser.ParseNode) error {
val, err := n.GetObjectValue(absser.CreateUntypedNodeFromDiscriminatorValue)
if err != nil {
return err
}
if val != nil {
e.SetTable(val.(absser.UntypedNodeable))
}
return nil
}
return res
}

Expand Down Expand Up @@ -166,6 +186,12 @@ func (m *UntypedTestEntity) Serialize(writer absser.SerializationWriter) error {
return err
}
}
{
err := writer.WriteObjectValue("table", m.GetTable())
if err != nil {
return err
}
}
{
err := writer.WriteAdditionalData(m.GetAdditionalData())
if err != nil {
Expand Down
15 changes: 14 additions & 1 deletion json_parse_node_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package jsonserialization

import (
"testing"

"github.com/microsoft/kiota-serialization-json-go/internal"
"github.com/stretchr/testify/require"
"testing"

absser "github.com/microsoft/kiota-abstractions-go/serialization"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -269,6 +270,17 @@ func TestUntypedJsonObject(t *testing.T) {

additionalData := testEntity.GetAdditionalData()
assert.NotNil(t, additionalData)

table := testEntity.GetTable().(*absser.UntypedArray)
assert.NotNil(t, untypedArray)
for _, row := range table.GetValue() {
rowValue := row.(*absser.UntypedArray)
assert.NotNil(t, rowValue)
for _, cell := range rowValue.GetValue() {
cellValue := cell.(*absser.UntypedDouble)
assert.NotNil(t, cellValue)
}
}
}

const TestUntypedJson = "{\r\n" +
Expand Down Expand Up @@ -306,6 +318,7 @@ const TestUntypedJson = "{\r\n" +
" }\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

0 comments on commit 70ad2fc

Please sign in to comment.