Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json schema validation in Spring REST APIs

I’m building a REST API using Spring Boot and [jackson-module-jsonSchema] (https://github.com/FasterXML/jackson-module-jsonSchema) for JSON schema generation. I’m looking the best way to validate the request JSON payload arriving to my APIs endpoints (Spring controllers) against the defined JSON schema defined for the exposed resource, validation includes check required fields , format , min and max values, etc.. everything we can validate against the schema.

Seems jackson json schema module is useful for schema generation but not for validation, am I right? Any suggestion on how to achieve what I’m trying to do?

like image 752
Alec Avatar asked Jan 18 '16 15:01

Alec


1 Answers

If you take a look at JSON schema site, there are only two libraries for validation in Java.

  1. The one that Jorge Campos suggested is mature, but looking for new maintainer: https://github.com/fge/json-schema-validator
  2. Second one is relatively new: http://github.com/everit-org/json-schema

I was recently in situation where I had to choose one or the other and I picked first option. It is being used also by Rest Assured library under the hood.

like image 187
luboskrnac Avatar answered Sep 21 '22 14:09

luboskrnac