Question: deserializing string as number
Hi.
We are considering switching to Utf8Json from Newtonsoft. From one of our external providers, we receive a json string, where we have something like: ... "someField": "123", ...
and in the corresponding object, we have: ... int somefield; ...
Newtonsoft knows how to treat the string properly and parse it as a number, while Utf8Json throws an exception with: expected:'Number Token', actual:'"0"', at offset:297
How can we fix that in Utf8Json?
Thanks.
Same problem. Help! Thanks.
I think that you'll have to create your own IJsonFormatterResolver and use it when serializing/deserializing to/from json. So: IJsonFormatterResolver intAsStringResolver = <Create the new resolver that will handle the issue>; String json = Utf8Json.JsonSerializer.ToJsonString(myObject, intAsStringResolver);
In the resolver, you'll have to implement IJsonFormatter
Hope this helps.
@yotamoron how did you create your own intAsStringResolver? I am having the same problem. Please help. Thanks