keenlabs / KeenClient-Java

Official Java client for the Keen IO API. Build analytics features directly into your Java apps.
https://keen.io/docs
MIT License
74 stars 43 forks source link

Android built-in JSON library may not reliably serialize nested maps #20

Closed Geeber closed 10 years ago

Geeber commented 10 years ago

At least one person has experienced an issue wherein certain devices' JSONObject implementation improperly serializes nested maps, producing:

{"keen":"{timestamp=...}", ...}

Instead of:

{"keen":{"timestamp":"..."}, ...}

The improper serialization results in JSON which the Keen API will not accept, returning a NamespaceTypeError. It's unknown how widespread this issue is, or why it's happening. However this may cause those devices to be unable to upload events using the Keen SDK.

Reports of additional devices experiencing this behavior would be greatly appreciated.

Geeber commented 10 years ago

This issue is probably related to (or maybe directly caused by) this bug:

https://code.google.com/p/android/issues/detail?id=55114

It looks like that issue was fixed in July of 2013, but any devices that haven't received that patch are probably not going to work properly. In order to support those devices, we will probably have to explicitly handle this case ourselves.

Geeber commented 10 years ago

Version 2.0.2 of the SDK includes the fix for this. I've tested with an SDK 14 emulator and reproduced the bug with 2.0.1, then verified that 2.0.2 works as expected. If anyone encounters this problem moving forward, please feel free to re-open.

Note that the patch only handles nested Maps and Collections. Other nested types that aren't handled by JSONObject will still cause problems.