java - Validating model - received from JSON (spring mvc) - good practices -


i have simple pojo class (models) created json format (received frontend).

what approach validate these values ? example if number not null, if number (nor string), etc.

you can use validate attributes annotation @valid in restcontroller , put @notnull or @notempty in model. exemple:

  @restcontroller     @requestmapping(value="/book")     public class bookcontroller {      @requestmapping(method=requestmethod.post)         public responseentity<void> save(@valid @requestbody book book){             //save book         }     }     @entity    public class book{      @notempty(message="msg")      private string name;    } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -