Closed zendril closed 4 years ago
Hello @zendril Thank you for good suggestion.
I am also the author of Joy, which is yet another implementation of JakartaEE JSON Processing API,
formerly called Java EE JSON Processing API defined in javax.json
package. One of the reasons I developed the Joy is parsing YAML natively with the same API as JSON. However the dream has not come true yet.
Justify depends only on JakartaEE API, not on any of its implementations. Therefore when I or you or somebody else achieves to implement the API with support of YAML, it can handle schemas and instances in YAML format for free, which is I really want to do.
I'm not sure I'm following you and the reference to Joy.
Basically what I'm saying is that you check if the file extension is yml or yaml. If so, then convert to json, then pass into the existing schema and instance parsing/validating..
Should be able to do the conversion, like so:
String convertYamlToJson(String yaml) {
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
Object obj = yamlReader.readValue(yaml, Object.class);
ObjectMapper jsonWriter = new ObjectMapper();
return jsonWriter.writeValueAsString(obj);
}
If I get some time I'll pull the code and take a look to see if it can be implemented and raise a PR.
@zendril I have almost done implementing a new YAML parser joy-yaml that conforms to the Jakarta JSON Processing API (JSON-P), with the help of snakeyaml-engine. This parser will be available instead of classic Joy in the coming release of Justify. No modification is needed to the side of Justify except that the Jakarta JSON Processing API must be upgraded to 2.x. We will be able to validate YAML documents with JSON schema natively without any conversion. Thank you for your suggestion!
Our instance document is in YML (which is a superset of json).
I would like to pass in a yml for both the schema and instance docs.
It is relatively trivial to support this as you can take yml and marshall it to json and then pass that to the validation. (I just contributed some code to a golang based json-schema validator and it works great.)