SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

Number format exception #196

Closed tunguski closed 7 years ago

tunguski commented 7 years ago

During tests I've found this response:

{
  "_exceptions": [{"exception":"java.lang.NumberFormatException","exception message":"For input string: '27096761719904980000'"}],
  "http status code":406,
  "http status description":"Not Acceptable",
  "message":"Invalid JSON"
}

Mentioned value seems to be a proper number regarding to JSON specification. I tried to find something about possible limitations in documentation (json, restheart), but did not find anything.

Is it a bug or am I missing something?

ujibang commented 7 years ago

Can you try with { "N": {"$numberLong": "27096761719904980000"}}

See https://docs.mongodb.com/manual/reference/mongodb-extended-json/#numberlong

tunguski commented 7 years ago

Yes, I assume it will work. For the fields I'm working with even simpler will be serialize them to string. I don't need to treat them as numbers in mongo. Still I need to implement this change in multiple places.

So I would like to be sure what is the reason. Is this as expected because a) it is a mongo restriction, b) it is a restheart limitation, c) or it is a bug, d) something else.

Could you tell me what is your view on that?

Thanks in advance!

mkjsix commented 7 years ago

There was quite a debate in the mongodb community about this issue, especially after some changes introduced by the Java driver release 3.x.

My opinion is that RESTHeart must stick to how the Java driver handles BSON serialization and deserialization as much as possible, or keeping our releases in synch with driver's would become excessively complex.

Below some references:

https://jira.mongodb.org/browse/DRIVERS-167 https://jira.mongodb.org/browse/JAVA-1272 https://jira.mongodb.org/browse/JAVA-1280 https://jira.mongodb.org/browse/JAVA-2173

mkjsix commented 7 years ago

I'm closing this, if you have additional questions feel free to re-open.