Domain Object Validation in Play / Scala

46 views
Skip to first unread message

Sujoy Datta

unread,
Nov 4, 2017, 11:43:14 AM11/4/17
to Play Framework
Hi ,

I am trying to implement some domain object validation in Play 2 with scala in my REST based project. For the same project which was  in java earlier we use oval for that purpose. Any one can help me out by any such kind of validation tool to work with case class or at the JSON conversion. Any thing do we have in play framework to do this kind of domain object validation.

Any help will be highly appreciated..

Miguel Ángel Moreno

unread,
Nov 6, 2017, 8:02:18 AM11/6/17
to Play Framework
FAR from being an expert myself, but I stumbled upon this recently


Perhaps it helps you to know where to validate the input during json parsing

Regards,
Miguel

Miguel Ángel Moreno

unread,
Nov 6, 2017, 8:10:07 AM11/6/17
to Play Framework
Sorry, I pressed "send" to quickly.

In my case, what I am doing, (I insist I am a beginner) is as follows:

- Json comes in the request
- When the validation is simple (for example, a filed is optional or must be a number, etc) I validate it using the Json Reads validation 
- The rest of validation I am doing it in the apply method of my companion object

object Something {
 
def apply(ar1: Int, ar2: String...) = {
   
assert(ar1 < 500)
   
assert (ar2 contains ("hello"))
   
....
 
}
}

That would be an example, in case it helps.

Miguel
Reply all
Reply to author
Forward
0 new messages