3

Given the following:

String a = '{"field":13316956360165196849}';
Map<String, Object> tokenObject = (Map<String, Object>) JSON.deserializeUntyped(a);

I get the error:

System.JSONException: For input string: "13316956360165196849" at [line:1, column:2]

However if I remove the last digit it deserializes fine

String a = '{"field":1331695636016519684}';
Map<String, Object> tokenObject = (Map<String, Object>) JSON.deserializeUntyped(a);

Any idea why having one character longer causes JSON to choke? Right now I do not have a work around and looking to get more info on what may be the cause

  • 32-bit integer limit, perhaps? – Derek F Feb 20 at 17:31
  • @DerekF Yea I was thinking that and if that is the case the only way around it will be to use regex to remove that field/value from the JSON. Im checking now to see if it is critical the value be present downstream....I have no control over the type so cannot get it change to a string – Eric Feb 20 at 17:32
6

My comment was close, this is an issue because the integer literal 13316956360165196849 overflows the 64-bit long

Max value for a long:
9,223,372,036,854,775,807 (10^18)

Your value:
13,316,956,360,165,196,849 (10^19)

| improve this answer | |
  • but the error For input string: "13316956360165196849" makes me think it was trying to deserialize it into a string due to the error? Or maybe just a bad message – Eric Feb 20 at 17:35
  • So basically the only way around is to remove it from the JSON string? A class to deserialize into is a worse option as a lot of the field names have . in them so I would still have to do a lot of manipulation or yuk write a parser. – Eric Feb 20 at 17:36
  • 2
    It'd be hard to represent a number too large for the platform to handle as anything other than a string in an error message though, and a value in JSON that isn't quoted and isn't true/false must be a number, yeah? – Derek F Feb 20 at 17:39
  • Makes sense. Removal it is – Eric Feb 20 at 17:40
  • Is there possibly a way to do a partial typed deserialization? Something that says "treat this one field as a string, and then deserialize everything else as a Map<String, Object>"? – Derek F Feb 20 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.