[TIMOB-26756] Android: Object details should be printed instead of "[object Object]" (parity)
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | None |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | android, ios, log, parity |
Reporter | Hans Knöchel |
Assignee | Jan Vennemann |
Created | 2019-01-21T06:15:50.000+0000 |
Updated | 2020-01-08T18:31:04.000+0000 |
Description
We noticed that logs between iOS and Android differ. On iOS, an object is printed with it's keys, so it can be inspected. On Android, it only prints
\[object Object\]
, requiring to manually stringify it. Unifying it would be a quick but useful improvement to the SDK.
When I tested the below, the behavior between Android and iOS were the same.
When concatenating a Titanium object to a JavaScript string, both Android and iOS return
"[object Object"
. AndJSON.stringify()
correctly returns a JSON of all of the object's enumerable properties on both Android and iOS. Can you give me a code snippet please? I'm curious where you're seeing the difference. Thanks.In our case, we very often log plain objects, e.g.
console.log({ hello: 'world' });
On iOS, it will be displayed "kind" of stringified - at least a bit formatted (which is done by the internal iOS logging of the underlayingNSDictionary
object). On Android, it does not attempt to show any key/values but onky the above[object Object]
. I hope that can reproduce it. But still no blocker, all okay!Okay. I've confirmed that both Android and Windows return
\[object Object\]
when doing the below.Interesting. iOS and Windows both use JavaScriptCore. So, I'm guessing we have written something custom on the iOS side to JSON stringify a dictionary. It's probably not a built-in JavaScriptCore things since the Windows results are the same as Android.
So, the below works on Titanium for Windows. It also works in node.js too. Not sure if it's a wise idea or not, but here it is.
Unfortunately, the above won't work on Android. Not sure why. But in the end, the solution is to
JSON.stringify()
the dictionary.[~jquick] That works on Android, I put it in the
ti.main.js
Oh interesting. It turns out the JS minify prevents the below from working, which is used by default when doing a "development" or "production" build. When you build for Android emulator (ie: "test" build), a JS minify does not happen and the below solutions works fine.
So, I got the above to work for a device/development build via the following command line...