I have a service in which I have to assign all the parameters of the request to a model object. The type of all parameters in request is String, while model has few fields as string and some as BigInteger. I'm using BigInteger's constructor with string parameter to do the conversion. However, the request can contain null values for some fields. So, one way is to check every field for null before calling the BigInteger constructor to prevent null pointer exception. Since, the number of field are pretty large, I want to know if I can use AOP? If so, what should be the pointcut expression?
Classic XY problem/question?
Simply create a factory method for BigInteger
and use this instead of the constructor:
public static BigInteger fromString(String bigIntString) {
if (bigIntString == null || bigIntString.length() == 0) {
return null;
}
return new BigInteger(bigIntString);
}
No need to leverage AOP and the complexity that comes with it for such a simple problem.