Facepunch / garrysmod-issues

Garry's Mod issue tracker
146 stars 56 forks source link

util.TableToJSON converts all integers to floats #3403

Open Deer292 opened 6 years ago

Deer292 commented 6 years ago

Details

Integers stored in a table, upon converting to JSON become floats.

This is, to my knowledge not normal behavior and is causing numerous issues when sending JSON payloads to a server that expects strict typing.

Steps to reproduce

lua_run local test = { ["test"] = 5 } lua_run MsgN(util.TableToJSON(test)) {"val":5.0}

This has only started happening since the update put out today.

willox commented 6 years ago

This must have been a behavioural change in rapidjson, which we've recently updated, but I'm pretty sure it is correct. 5 and 5.0 should be equivalent in JSON.

What server is differentiating between integers and doubles in the payload?

Deer292 commented 6 years ago

The JSON payload is being sent to my custom inventory server which uses JSON.net and throws an exception as it does not see 5.0 as a valid integer.

willox commented 6 years ago

I can see that this is annoying for your circumstances, but it's not something I see as a priority to fix - util.TableToJSON is abiding to the JSON standard. That said, if I'd noticed this difference before the patch I certainly would've tried to avoid it.