AdaptiveCards: Bot Builder v4 IgnoreEmptyItemsConverter causes an issue when ReadJson
Platform
Bot Builder v4.0 (dotnet core)
Author or host
web api (Bot Framework)
Version of SDK
1.1
Issue
When deserialize the DialogState which contains the AdaptiveCard, it fails with error "Error reading JArray from JsonReader at
var array = JArray.Load(reader);.
Error: Current JsonReader item is not an array: StartObject. Path 'DialogState.DialogStack.$values[0].State.dialogs.DialogStack.$values[0].State.options.Prompt.attachments.$values[0].content.action"
This caused by [JsonConverter(typeof(IgnoreEmptyItemsConverter<AdaptiveAction>))] attribute on AdaptiveCard which will be called while deserialization but it’s not actually an array yet, as $value holds an array not action (nor body)
"actions": {
"$type": "System.Collections.Generic.List`1[[AdaptiveCards.ActionBase, AdaptiveCards]], System.Private.CoreLib",
"$values": [
{
"$type": "AdaptiveCards.SubmitAction, AdaptiveCards",
"type": "Action.Submit",
"data": "Test",
"title": "Test"
}
]
}
We should try/catch JArray.Load
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 18 (5 by maintainers)
Thank you, this helps.
So it looks like the problem is the Adaptive Card object model isn’t fully compatible with NewtonSoft’s JSON serialization/deserialization algorithm when TypeNameHandling.All is used. Namely, an AdaptiveCard object cannot be round-tripped (FromObject then ToObject) in TypeNameHandling.All mode.
I’ll leave it to @khouzam and @paulcam206 from here (maybe they had already understood all this for that matter.)