Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

object validation and messages  RSS feed

 
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
 
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()
 
Marshal
Posts: 59705
187
  • 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!