JSON in PostgreSQL with application side validation

I was looking for a way to validate JSON data structure with the schema saved in the database. PostgreSQL has a very cool way to store json in JSONB fields but the question was how to validate this without extra PostgreSQL plugins and integrated in hibernate’s lifecycle with bean validation.

Under https://github.com/mbogner/schema-validator I came up with a solution that enables you to validate against a JSON Schema or against a custom map that holds schema information. Both values can be stored in the database and validate a map that can be used to map JSONB fields. It is based on a javax.validation class level validator that allows you to have your json as a map and your schema in a second field.

Checkout https://github.com/mbogner/schema-validator to see the code. I would be happy to hear your opinion or other ways to reach the goal in a maybe easier way.