I\'m getting the following exception.
Caused by:
java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Integer
As we see from the javaDoc, BigInteger is not a subclass of Integer:
java.lang.Object java.lang.Object
java.lang.Number java.lang.Number
java.math.BigInteger java.lang.Integer
And that's the reason why casting from BigInteger to Integer is impossible.
Casting of java primitives will do some conversion (like casting from double to int) while casting of types will never transform classes.