schema:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$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" | |
] | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>com.doctusoft</groupId> | |
<artifactId>json-schema-java7</artifactId> | |
<version>1.4.1</version> | |
</dependency> |