[play-java 2.5.x] JSON validation

447 views
Skip to first unread message

raunak

unread,
Mar 17, 2016, 6:09:23 PM3/17/16
to play-framework
Is there a way to validate JSON body (from a request) to ensure the required fields are there, just like form validation? 

I'm using play-java, version 2.5

Thanks
Raunak 

Илья Толлю

unread,
Mar 18, 2016, 5:10:06 PM3/18/16
to play-framework
Hello, Raunak!

Or course, there is: https://www.playframework.com/documentation/2.5.x/ScalaJsonCombinators#Validation-with-Reads

пятница, 18 марта 2016 г., 1:09:23 UTC+3 пользователь raunak написал:

Илья Толлю

unread,
Mar 18, 2016, 5:11:34 PM3/18/16
to play-framework
Oh, sorry, I've noticed that you talk of Play Java only after the answer had been sent. 


пятница, 18 марта 2016 г., 1:09:23 UTC+3 пользователь raunak написал:
Is there a way to validate JSON body (from a request) to ensure the required fields are there, just like form validation? 

raunak

unread,
Mar 19, 2016, 1:04:58 PM3/19/16
to play-framework
Yes, looking to do it in Java. Its been possible to do so in scala as far as I can remember. Though, I think its possible to do it in Java in 2.5 as well, just not sure how, yet! :)

raunak

unread,
Mar 24, 2016, 8:50:41 AM3/24/16
to play-framework
Does anyone have suggestions? I haven't found anything in the docs so far.. 

Greg Methvin

unread,
Mar 24, 2016, 8:54:38 AM3/24/16
to play-framework
This is maybe more of a Jackson question than a Play one. Maybe you can try posting on their mailing list.

On Thu, Mar 24, 2016 at 5:50 AM, raunak <rauna...@gmail.com> wrote:
Does anyone have suggestions? I haven't found anything in the docs so far.. 

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/f448b71c-b821-4bcc-906e-5b78a049b90d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Senior Software Engineer

raunak

unread,
Mar 24, 2016, 10:55:29 AM3/24/16
to play-framework
Thanks Greg - will let the folk here know if I learn something :)

ßìnòy S

unread,
Jul 8, 2016, 11:11:45 AM7/8/16
to play-framework
Raunak, 

How did you finally implement this ?

raunak

unread,
Jul 8, 2016, 1:21:21 PM7/8/16
to play-framework
After doing some research, i had two options available. Depending on your use case, you can pick either, as for me, I went with option 1. 

2. Use @JsonProperty(required=true), which is similar to @Constraints.Required in Play.

Raunak
Reply all
Reply to author
Forward
0 new messages