mgholam / fastJSON

Smallest, fastest polymorphic JSON serializer
https://www.codeproject.com/Articles/159450/fastJSON-Smallest-Fastest-Polymorphic-JSON-Seriali
MIT License
478 stars 148 forks source link

Parsing bad data getting parsed correctly #95

Closed tchristian32 closed 5 years ago

tchristian32 commented 5 years ago

We have an object that has an int as a property:

public class SomeData { public int UserId; }

If I pass data like this: { "UserId" : "G" }

JSON.ToObject<SomeData>(payload) will convert the G into an int, 23 I believe. This also happens if I pass "AG" or even "'" (a single quote).

This means that if someone passes G or something else to my API, I will happily convert it to some random number and then try to act on that User (assuming I have that ID in my system). Is there a way to either disable that conversion or control it in some way?

mgholam commented 5 years ago

Hehe! an interesting side effect of the Helper.AutoConv() and the Helper.CreateInteger(string,...) methods.

It is possible to add a config to enable/disable auto converting, and in your case if disabled you would get an error [which I presume is what you want].

tchristian32 commented 5 years ago

Yes that is what I want in this situation. How can I disable auto converting? Thanks!

mgholam commented 5 years ago

try v2.2.1

mgholam commented 5 years ago

I have added JSONParameters.AutoConvertStringToNumbers

tchristian32 commented 5 years ago

Thanks! Pulling that down now