JSON Schema and Bean Validation

409 views
Skip to first unread message

Alex Soto

unread,
Oct 4, 2016, 6:57:17 AM10/4/16
to MicroProfile
One of the things that I normally miss is  that when I have code like:


 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.TEXT_PLAIN)
 @POST
 public Response check(final JsonObject data) {    
 }

I need to do a lot of code like if data contains user then get string, if data contains age and age is an integer greater than 0 then get int and so on.

Maybe it could be interesting to add JSON schema support in bean validation/whatever so we can set a json schema like expression or json schema file and it is validated.

WDYT?

Werner Keil

unread,
Oct 4, 2016, 10:11:31 AM10/4/16
to MicroProfile
Not sure, if it would (like other ideas in prior threads like JWT) fall into Bean Validation or more either (or both) of the JSON JSRs
- JSON-P
- JSON-B

Either way, having Bean Validation 2 just started and JSON-B 1.0 not yet finished (JSON-P 1.1 also needs a bit more final brush before it's ready for Java EE 8 but it seems nearly as far as JSON-B, e.g. it already got a 1.0 TCK) there should be room to do this in the right place or places.

Werner

Gunnar Morling

unread,
Oct 9, 2016, 4:20:18 AM10/9/16
to MicroProfile
Hi,

The JSON-P/B specs would be the right place for adding JSON schema support. And JAX-RS possibly to execute validation of JSON payloads upon request execution.

Applying Bean Validation constraints to JsonObject would be another interesting idea. Right now Bean Validation is centered around JavaBeans types. So we would need a more abstract concept of what a "type" is, an API for applying constraints to non JavaBeans types (because you couldn't use annotations) and an SPI for obtaining property values from alternative type models.

That's nothing that's done in a half day, but for sure very interesting to explore in the reference implementation.

--Gunnar

Alex Soto

unread,
Oct 9, 2016, 6:16:56 AM10/9/16
to MicroProfile
I can implement json schema in JSON P

Alex

Werner Keil

unread,
Oct 9, 2016, 11:08:35 AM10/9/16
to MicroProfile
Do you still see that realistic for JSON-P 1.1?

Werner

Alex Soto

unread,
Oct 9, 2016, 11:21:02 AM10/9/16
to MicroProfile
Depending in the dates we are talking to release.

Werner Keil

unread,
Oct 9, 2016, 6:13:12 PM10/9/16
to MicroProfile
As of now 1.1 should aim for the Java EE 8 release train. Scheduled until "the end of 2017". 

In my JavaOne presentation I mentioned, that "Big JSON" which I could not spot work alread done was maybe something likely to postpone till a Java EE 9 version.
Also could go well along the whole NoSQL/Big Data aspects EE 9 hopes to include.

Except minor tweaks like interface vs. concrete class, JsonPointer and JSonPatch look fairly complete, so depends how big JSON Schema would be.
Also does "The latest IETF published draft is v4" in http://json-schema.org/documentation.html suggest, there are no final RFCs for it yet?
Reply all
Reply to author
Forward
0 new messages