Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validates multidimensional collections scenarios using UntypedNode #135

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
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