Rajat Goel Rajat Goel - 1 year ago 67
Java Question

how to prevent user from entering decimal values in integer fields in REST APIs in spring in java

Spring is automatically converting Decimal values to Integers while using POST Method in REST APIs. While, I want to throw a custom exception if user enters Decimal values. Is there any easy way to do this.

Eg:: If user enters age = 4.3 , then Spring is converting it to 4.

Answer Source
if (age instanceof Integer) //dowork();
else //throw custom exception

consider age as type Object and then use the above code to do your testing.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download