I have read this link to parse Json to a predefined object. https://stackoverflow.com/a/48904120. How can we then incorporate the .schema files provided to help with validation or parsing to the JsonElement?
2 Likes
This is what I did:
val schema = SchemaLoader.forURL(
this::class.java.getResource("/schema/restaurants.schema")!!.toString()
).load()
val validator = Validator.forSchema(schema)
Not sure if it’s “good”, but it works (it performs validation as expected).
It operates on the JSON object, so you would then separately deserialize into an object, but that doesn’t matter imo
2 Likes
As it turns out, this was wrong. The following should work better:
val schema = SchemaLoader.forURL(
"classpath:/schema/scenario.schema"
).load()