HubSpot / slack-client

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

Fix profile fields parsing #168

Closed omotnyk closed 4 years ago

omotnyk commented 4 years ago

After #114 was released adding fields to UserProfile model, we noticed that our service occasionally fails deserializing user profile. It turns out that Slack sends us [] instead of {} sometimes. Since we expect fields to be a Map we cannot deserialize this property and fail with Cannot deserialize instance ofjava.util.LinkedHashMapout of START_ARRAY token at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.hubspot.slack.client.models.events.SlackEventWrapper$Json["event"]->com.hubspot.slack.client.models.events.user.SlackUserChangeEvent$Json["user"]->com.hubspot.slack.client.models.users.SlackUser$Json["profile"]->com.hubspot.slack.client.models.users.UserProfile$Json["fields"]) error.

Long term, I communicated to Slack support and they logged a bug so eventually, their team should get to it. The issue is not public so I'm not able to link it here. Short term, I added this custom deserializer to handle this specific bug in Slack Events API and return Optional.empty() if we received an array.

Affected users: Potentially everyone who listens to user_change webhooks from Slack Events API.

I added a UT to cover this specific case with a broken webhook payload.

Tagging @jonathanwgoodwin as it might affect the solution he needs fields for as well.

[JsonParser::skipChildren](https://fasterxml.github.io/jackson-core/javadoc/2.5/com/fasterxml/jackson/core/JsonParser.html#skipChildren()) docs.