Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to avoid many if else [Pojo Validation]

 
saqib sarwar
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a validation class for eight types of messages(POJO classes) which first identifies the message class and than validate its properties.

now a pojo message class has about 46 properties, and validating these properties with if-else and then logging every validation error basicallly made the code too long and hard to read and maintain.

i want to improve my code and looking for a way to avoid many if-else statement or good way to validate pojo objects.

can any one suggest a way to move forward ?
 
Jilesh Lakhani
Ranch Hand
Posts: 49
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i have a sample code
 
saqib sarwar
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually the sample is tooooo big that it will confuse you guys ...

today i found solution about this, and now i will use JaValid

i walked through commons commons validators, i-screen and Spring validation as we are using Spring 2.0.

but i want to keep code away from xml and I cannot use Spring 2.5 annotation based validation because our project is bound to spring 2.0.

so i decided to use JaValid..

hope i would have good experience with this .. it looks like a simple annotation based framework for validation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic