Instantly share code, notes, and snippets.

What would you like to do?
package testapp;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
public class FastJson37IssueWithLongParsing {
public static class LongVal {
private long v;
public void setV(long v) {
this.v = v;
public String toString() {
return String.valueOf(v);
public static void main(String[] args) {
String fastJsonVersion = JSON.VERSION;
System.out.println("fastjson version: " + fastJsonVersion);
BigInteger n = new BigInteger(String.valueOf(Long.MAX_VALUE)).add(new BigInteger("1"));
Map<String, BigInteger> map = new HashMap<>();
map.put("v", n);
String strBad = JSON.toJSONString(map);
System.out.println("prepare to parse: " + strBad);
System.out.println("We expect the following line to raise NumberFormatException, but it will print out something:");
System.out.println(JSON.parseObject(strBad, LongVal.class));
System.out.println("While Long.parseLong(String) call does raise NumberFormatException:");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment