Clarification on ParseNode Usage
dadams39 opened this issue · 4 comments
Creating an issue because I do not see the discussion area.
Continuing the conversation on the ParseNodes. Object is Hydrated and all the content is within the Parsenode. Code recap:
parseNode, _ := js.NewJsonParseNodeFactory().GetRootParseNode("application/json", result)
deserializedValue, err := parseNode.GetObjectValue(models.CreateMessageFromDiscriminatorValue)
if err != nil{
t.Errorf("ERROR: %v\n", err)
}
I believe the previous conversations help us to understand that if we print the type and values of deserialized value we would retrieve something like this.
ParseNode: *models.Message &{{{map[@odata.context:0x14000281f40 value: [0x140002b0c60 0x140002b1950 0x140002d6650....
This is fine so far. The parsable interface gives us this deserializedValue.GetFieldDeserializers()
that returns as described -> GetFieldDeserializers() map[string]func(ParseNode) error
What is unclear is how to get the value that the func(ParseNode) holds for example:
values := deserializedValue.GetFieldDeserializers()
fmt.Printf("%v\n", values")
// map[attachments:0x100abf710 bccRecipients:0x100abf580 body:0x100abf4a0 bodyPreview:0x100abf3e0 categories:0x100ac2650 ccRecipients:0x100abf250 changeKey:0x100ac2590 conversationId:0x100abf190 ...
// How to get the value of bodyPreview?
bp := values["bodyPreview"]
fmt.Printf(%T \t %v\n", bodyPreview, bodyPreview )
the GetFieldDeserializers returns a set of callbacks that are used by the ParseNode to deserialize the object. These are not meant to be used by an SDK user and are internal to the serialization/deserialization process.
Once you have obtained the deserializedValue
, simply call deserializedValue.GetBodyPreview()
which returns a pointer to a string. If the value is not nil, dereference it, and you'll get the string representation.
Ummm.
test.go:53:52: deserializedValue.GetBodyPreview undefined (type serialization.Parsable has no field or method GetBodyPreview)
if you try aMessage, err := models.CreateMessageFromDiscriminatorValue( deserializedValue )
the result is:
deserializedValue.GetBodyPreview undefined (type serialization.Parsable has no field or method GetBodyPreview)
Thoughts?
Sorry, I forgot that you need to type assert first.
deserializedValue.(Messageable).GetBodyPreview()
That's the one. I appreciate it!
I found an interesting thing that a set of messages ( as defined by Graph explorer) can be parsed directly into the object. Thus, it would appear to be a message and none of the methods would function. I'll look into that more on my end in the future.