21 August 2020

Json Schema sample

 

schema:
package cl.ejemplo.json.schema;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.everit.json.schema.Schema;
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;
import org.json.JSONTokener;
public class JSONSchemaTest {
public static void main(String[] args) {
//absoluto
//String path = "/Users/German/development/workspace/" +
//relativo
String path = "src/test/resources/";
System.out.println("path=" + System.getProperty("user.dir"));
try (InputStream inputStream = new FileInputStream( path + "journal_schema_test.json") ) {
//try (InputStream inputStream = jst.getClass().getResourceAsStream("/path/to/your/schema.json")) {
JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
Schema schema = SchemaLoader.load(rawSchema);
schema.validate(new JSONObject("{\n" +
" \"title_schema\": \"Journal nuevo\",\n" +
" \"version_schema\": \"1.0.0\",\n" +
" \"id_schema\": 1,\n" +
" \n" +
"\"dataAuditoria\":{\"accion\":\"Descarga PDF ConstanciaCupoTarjetaCred_8027284-7_2019-03-18.pdf\"}\n" +
"\n" +
"}\n" ));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("fin.");
}
}
json schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id_schema": "1",
"title": "Journal nuevo",
"description": "persistencia en el modelo de Journal",
"version": "1.0.0",
"type": "object",
"definitions": {
"dataAuditoria": {
"type": "object",
"properties": {
"accion": {
"type": "string"
},
"seccion": {
"type": "string"
}
}
}
},
"properties": {
"id_schema": {
"description": "identificador unico",
"type": "integer"
},
"title_schema": {
"description": "detalles del schema",
"type": "string"
},
"version_schema": {
"description": "versionamiento semantico",
"type": "string"
},
"dataAuditoria": {
"$ref": "#/definitions/dataAuditoria"
}
},
"required": [
"id_schema",
"title_schema",
"version_schema"
]
}
pom.xml:
<dependency>
<groupId>com.doctusoft</groupId>
<artifactId>json-schema-java7</artifactId>
<version>1.4.1</version>
</dependency>

Algorithms and Data Structures in Action

Technical proofer/reviewer:

Marcello La Rocca
MEAP began July 2019 Publication in Spring 2021 (estimated)
ISBN 9781617295485 325 pages (estimated) printed in black & white

https://www.manning.com/books/algorithms-and-data-structures-in-action

https://github.com/mlarocca/AlgorithmsAndDataStructuresInAction


UPDATE: February 2021





Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.