users@jersey.java.net

[Jersey] Re: Enabling bean validation

From: Oliver B. Fischer <mailsink_at_swe-blog.net>
Date: Wed, 23 Apr 2014 16:53:32 +0200

Now I got it. RTFM! ;-)

Thank you!

Am 23.04.14 16:43, schrieb Michal Gajdos:
> Hi Oliver,
>
> this area is described in JAX-RS 2.0 spec [1], chapter 7.3 Entity
> Validation or in the BV spec [2]. Basically you need to tell underlying
> BV engine to validate an input param (via @Valid or via specialized
> constraint annotation). In your case @Valid would be enough. Take a look
> at the example from the JAX-RS spec:
>
> JAX-RS: Java API for RESTful Web Services @Path("/")
> class MyResourceClass {
>
> @POST
> @Consumes("application/xml")
> public void registerUser(@Valid User user) { ... }
> }
>
> [1] https://jcp.org/aboutJava/communityprocess/final/jsr339/index.html
> [2] http://beanvalidation.org/1.1/spec/
>
> Michal
>
> On 23.04.2014, 16:29 , Oliver B. Fischer wrote:
>> Hi Michal,
>>
>> thanks for the hints. I called isEnabled() always in the ctor of the
>> application and now it is clear why it returnd false. Now I obtain the
>> configuration via
>>
>> @Context Configuration config
>>
>> Afterwards I can call config.isEnabled(ValidationFeature.class) and it
>> returns true. That is great.
>>
>> One question more: How do I ensure that an entity will be validated
>> before it will be overhanded to a resource method? I use
>> jersey-media-json-jackson to map JSON to an annotated entity. But the
>> entity is never validated. At least it seams so to me. The class is
>> annotated with some @NotNull annotations but I never get constraint
>> validations.
>>
>> BTW, the code is online at
>> https://bitbucket.org/obfischer/jersey-playground/src/0703ae28873a/beanvalidation-simple/src/main/java/net/sweblog/jerseyplayground/beanvalidationsimple/b/?at=master
>> available.
>>
>> Thanks,
>>
>> Oliver
>>
>> Am 23.04.14 09:40, schrieb Michal Gajdos:
>