Skip to content

Instantly share code, notes, and snippets.

@mwmitchell
Created November 1, 2013 18:48
Show Gist options
  • Save mwmitchell/7270012 to your computer and use it in GitHub Desktop.
Save mwmitchell/7270012 to your computer and use it in GitHub Desktop.
boiler plate code for validation using custom ref path
(import '[com.github.fge.jsonschema.main JsonSchemaFactory])
(import '[com.github.fge.jackson JsonLoader])
(import '[com.github.fge.jsonschema.load.configuration LoadingConfiguration])
(import '[com.github.fge.jsonschema.load Dereferencing])
(import '[com.fasterxml.jackson.databind.node ObjectNode])
(let [cfg (.dereferencing
(.setNamespace
(LoadingConfiguration/newBuilder)
"resource:///schema-file-dir-on-classpath/")
Dereferencing/CANONICAL)
obj (JsonLoader/fromResource "/schema-file-dir-on-classpath/my-schema.json")
f (JsonSchemaFactory/newBuilder)
_ (.setLoadingConfiguration f (.freeze cfg))
schema (.getJsonSchema (.freeze f) obj)]
(.asJson (.validateUnchecked schema (ObjectNode. nil))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment