Skip to content

Fix subscriber attributes JSON for old Android devices#144

Merged
vegaro merged 3 commits into
masterfrom
cesar_fix_subscriber_attributes_json
May 19, 2020
Merged

Fix subscriber attributes JSON for old Android devices#144
vegaro merged 3 commits into
masterfrom
cesar_fix_subscriber_attributes_json

Conversation

@vegaro

@vegaro vegaro commented May 19, 2020

Copy link
Copy Markdown
Member

https://stackoverflow.com/a/12155874

We are calling JSONObject(body) and body is Map<String, Map> so in Android < 19 we send this:

"attributes":"{$displayName={value=cesar, updated_at_ms=1589043738052}}"}

In Android >=19 we send it correctly:
{"attributes": {"$displayName": {"value": null, "updated_at_ms": 1589042480440}}}

Comment on lines +109 to +111
val mapWithoutInnerMaps = mapValues { (_, value) ->
value.tryCast<Map<String, Any?>>(ifSuccess = { convert() })
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ kotlin functional programming.
Maybe we could leave a comment here explaining why this is needed, for future reference? So that a future dev doesn't come here, see this and say "wait, this isn't needed in modern android" and just kills the line

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, yeah good point, it took me a while to get this to work actually

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment here

@vegaro vegaro merged commit 1923b61 into master May 19, 2020
@vegaro vegaro deleted the cesar_fix_subscriber_attributes_json branch May 19, 2020 20:29
@vegaro vegaro mentioned this pull request May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants