• Post Reply Bookmark Topic Watch Topic
  • New Topic

object validation and messages  RSS feed

 
Udayan Kumar
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

In my current app which is invoked by an external application the interface is a single method with a custom java object as its method parameter.
The first step in the implemenation code is to validate this custom java input object.

The custom object comprises of lot many attributes so accordingly our code looks something like this

if(Helper.isBlank(input.getAttrib1()) || input.getAttrib2 == null)
return false;

In all cases of input validation failure we are passing a generic message back to the external app like "Input validation failed". We want to send back a message something like "attrib 1 cannot be blank" or "attrib2 cannot be null" type of message.

How can I implement such a check in a generic fashion applicable to all attributes and not doing it per attribute basis.

Let me know your thoughts.

Thanks
Uday
 
Tom Tillinghast
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection would be one way.

take a look at Object.getClass().getDeclaredFields() and Object.getClass().getFields()
 
Campbell Ritchie
Marshal
Posts: 55758
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't enforce that in the constructors and setXXX methods of the objects passed?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!