Number (@NotNull BigInteger value) { // don't forget to update toBigInteger() after changing this method final int intValue = value.intValue(); if (BigInteger.valueOf(intValue).equals(value)) { return intValue; } final long longValue = value.longValue(); if (BigInteger.valueOf(longValue).equals(value)) { return longValue; } return value; }