I use sf.json library to map form data for incoming request in my web application in java.
Lets say the incoming request is http://localhost:8080/app/addProfile with form data as:
formData: {
"name":"applicant Name",
"Age":"26",
"academics":{
"college":"80",
"inter":"67",
"matriculation":"89"
},
"skill":{
"computer":"c,c++,java",
"maths":"limit,permutation,statistics"
},
"dateOfBirth":"09-07-1988"
}
Server Side :
String requestFormData=request.getParameter("formData");
JSONObject formData = JSONObject.fromObject(requestFormData);
String name= formData.getString("name");
if(name.length>70){
//error message for length validation
}
if(!name.matches("regex for name"){
//error message for name validation
}
...
...
...
The main problem with this approach is if there is minor modification in the JSON
structure, then the entire code needs to be modified.
Is there is any api where i can configure the rules which are required for validation?