I'm trying to cast a string which is meant to be a BigInteger for key ID's in my mysql database calls for later. My JAVA is not the best, I can't seem to find a solution to turn my string back into a BigInt without getting any errors. Can someone please help?
String getWPU(final HttpServletRequest request, final HttpServletResponse response) {
BigInteger identifier = null
def wpu = request.getParameter('slip')
if (wpu?.size() > 0) {
LOG.debug('using ID as user identifier: {}', wpu)
identifier = new BigInteger(wpu);
}
identifier
}
I'm trying to follow solutions and don't get the expected result's. I'm feeling rather stupid today. Please put me out my misery. Here's my next attempt from reading around:
def wpu = request.getParameter('slip')
if (wpu?.size() > 0) {
LOG.debug('using wordpress slip as user identifier: {}', wpu)
}
BigInteger identifier = new BigInteger(wpu);
identifier
Which gives the following error when installing the JAVA project with Maven.
Cannot cast object '124' with class 'java.lang.String' to class 'java.math.BigInteger'
EDIT THE SOLUTION WAS THIS, as stated in duplicate answers but applied to my use case:
def wpu = request.getParameter('slip')
if (wpu?.size() > 0) {
LOG.debug('using wordpress slip as user identifier: {}', wpu)
}
BigInteger identifier = new BigInteger(0);
identifier.add(new BigInteger(wpu));
identifier