HubSpot / slack-client

An asynchronous HTTP client for Slack's web API
Apache License 2.0
115 stars 53 forks source link

OptionOrOptionGroup cannot be deserialized #130

Closed lightbody closed 4 years ago

lightbody commented 4 years ago

Describe the bug When sending a payload that contains BlockKit with a StaticSelectMenu or StaticMultiSelectMenu (and likely ExternalMultiSelectMenu though I haven't tested that), the request goes through fine but deserializing the response (if it includes the view just sent) will fail with an error like so:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.hubspot.slack.client.models.blocks.objects.OptionOrOptionGroup` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.hubspot.slack.client.models.response.views.ModalViewCommandResponse$Json["view"]->com.hubspot.slack.client.models.response.views.ModalViewResponse$Json["blocks"]->java.util.ArrayList[2]->com.hubspot.slack.client.models.blocks.Section$Json["accessory"]->com.hubspot.slack.client.models.blocks.elements.StaticSelectMenu$Json["initial_option"])

It appears Jackson needs a bit of extra coaching to be told how to deserialize the OptionOrOptionGroup fields in those objects. The pattern used elsewhere (ex: @JsonSubTypes) doesn't quite work here since there isn't a clear type indicator. Unfortunately, my Jackson skills aren't strong enough to get you a PR right now, so logging this bug until I gain said skills :)

Thanks!

lightbody commented 4 years ago

Btw, it looks like Jackson may not support this natively, but this may be of help:

https://stackoverflow.com/questions/24263904/deserializing-polymorphic-types-with-jackson/55333395#55333395

johnnyleitrim commented 4 years ago

Thanks for the bug report @lightbody!