• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

object validation and messages

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reflection would be one way.

take a look at Object.getClass().getDeclaredFields() and Object.getClass().getFields()
 
Marshal
Posts: 79512
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't enforce that in the constructors and setXXX methods of the objects passed?
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic