delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

Json result containing null value are converted to {"$InfNaN":0} #129

Closed Liryna closed 7 years ago

Liryna commented 7 years ago

Hi,

When calling myMethod, the string result onSuccess seems to replace all null value by {"$InfNaN":0}

mMeteor.call("myMethod", new Object[] { arg1, arg2 }, new ResultListener() { });

Meteor function output just before return: { "key": null } Android-DDP result string onSuccess { "key":{"$InfNaN":0} } I don't know if this is normal or should I probably convert it in a way to get my null value ?

Thanks again for the work :heart:

ocram commented 7 years ago

Thanks a lot!

EJSON, Meteor's JSON extension, uses

because these don't have corresponding representations in vanilla JSON.

But I don't really see why this should be happening for null, as opposed to NaN. Could you share an exemplary endpoint at a public URL so that we can re-produce this? Anyway, most likely, your Meteor server is already outputting that "wrong" JSON since this library on Android does not use the EJSON expression in any place. So the question is: Why is your server returning NaN when it should return null? Can you check your code?

See also: https://github.com/meteor/meteor/blob/b6c2991a28b2ac4e635081133360b55c1e4387f6/packages/ejson/ejson.js#L103

Liryna commented 7 years ago

Hi @ocram ,

Thanks for the quick reply, I don't currently have a public URL to give you 😢 I will try to create one next week with a sample project if I can.

Otherwise, I am pretty sure I return correctly the json with null 😢 Do you have an idea what can make meteor change it ?

ocram commented 7 years ago

@Liryna That sounds good!

In order to debug this, you could (temporarily) just return { "key": null } or even null directly. If you had a method that just returned that, without any further code, it would be easier to debug.

I can definitely confirm that I've seen several implementations where null is correctly returned as null.

Liryna commented 7 years ago

@ocram I will not be able to give an example here sorry 😢 Do you want me to close the issue ?

ocram commented 7 years ago

Oh, that's unfortunate. You know, the problem is that we really can't re-produce this, and null has always worked fine without being converted to those strings you mentioned. I'm afraid closing is the only thing we can do for now, yes. Sorry!