Skip to content

Commit

Permalink
Merge branch 'main' of https:/michaeldcanady/kiota-serial…
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Canady committed Aug 13, 2024
2 parents 3447cae + 28b99ec commit ef81011
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
41 changes: 23 additions & 18 deletions json_parse_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func loadJsonTree(decoder *json.Decoder) (*JsonParseNode, error) {
i, err := number.Int64()
c := &JsonParseNode{}
if err == nil {
c.SetValue(&i)
c.setValue(&i)
} else {
f, err := number.Float64()
if err == nil {
c.SetValue(&f)
c.setValue(&f)
} else {
return nil, err
}
Expand All @@ -101,42 +101,42 @@ func loadJsonTree(decoder *json.Decoder) (*JsonParseNode, error) {
case string:
v := val
c := &JsonParseNode{}
c.SetValue(&v)
c.setValue(&v)
return c, nil
case bool:
c := &JsonParseNode{}
v := val
c.SetValue(&v)
v := token.(bool)
c.setValue(&v)
return c, nil
case int8:
c := &JsonParseNode{}
v := val
c.SetValue(&v)
v := token.(int8)
c.setValue(&v)
return c, nil
case int32:
c := &JsonParseNode{}
v := val
c.SetValue(&v)
v := token.(byte)
c.setValue(&v)
return c, nil
case int64:
c := &JsonParseNode{}
v := val
c.SetValue(&v)
v := token.(float64)
c.setValue(&v)
return c, nil
case float32:
c := &JsonParseNode{}
v := val
c.SetValue(&v)
v := token.(float32)
c.setValue(&v)
return c, nil
case float64:
c := &JsonParseNode{}
v := val
c.SetValue(&v)
v := token.(int32)
c.setValue(&v)
return c, nil
case byte:
c := &JsonParseNode{}
v := val
c.SetValue(&v)
v := token.(int64)
c.setValue(&v)
return c, nil
case nil:
return nil, nil
Expand All @@ -146,8 +146,13 @@ func loadJsonTree(decoder *json.Decoder) (*JsonParseNode, error) {
return nil, nil
}

// SetValue sets the value represented by the node
// SetValue is obsolete, parse nodes are not meant to be settable externally
func (n *JsonParseNode) SetValue(value interface{}) {
n.setValue(value)
}

// setValue sets the value represented by the node
func (n *JsonParseNode) setValue(value interface{}) {
n.value = value
}

Expand Down
4 changes: 2 additions & 2 deletions json_parse_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ func TestParsingTime(t *testing.T) {
assert.Nil(t, err)
time1, err := someProp.GetTimeValue()
assert.Nil(t, err)
assert.Regexp(t, "^2023-07-12 08:54:24 [-+]", time1.String())
assert.Equal(t, "2023-07-12 08:54:24", time1.Format("2006-01-02 15:04:05"))

someProp2, err := parseNode.GetChildNode("withZone")
assert.Nil(t, err)
time2, err := someProp2.GetTimeValue()
assert.Nil(t, err)
assert.Contains(t, time2.String(), "2023-07-12 09:54:24 +")
assert.Equal(t, "2023-07-12 09:54:24", time2.Format("2006-01-02 15:04:05"))
}

func TestThrowErrorOfPrimitiveType(t *testing.T) {
Expand Down

0 comments on commit ef81011

Please sign in to comment.