验证json是否符合schema格式; 类生成JSON scheme;
JsonSchemaUtil provides json schema verification. If the verification is successful, it returns TRUE, and if the verification fails, it returns FALSE.
String json = "{\"name\":\"TOM\",\"age\":23,\"declawed\":false,\"description\":\"TOM loves to sleep all day.\"}";
String jsonSchema = "{\"$schema\":\"http://json-schema.org/draft-04/schema#\",\"title\":\"cat\",\"properties\":{\"name\":{\"type\":\"string\"},\"age\":{\"type\":\"number\",\"description\":\"Your cat's age in years\"},\"declawed\":{\"type\":\"boolean\"},\"description\":{\"type\":\"string\"}},\"required\":[\"name\",\"age\",\"declawed\"]}";
System.out.println(JsonSchemaUtil.validate(json, jsonSchema));
String json = "{\"name\":\"TOM\",\"age\":23,\"declawed\":false,\"description\":\"TOM loves to sleep all day.\"}";
String jsonSchema = "{\"$schema\":\"http://json-schema.org/draft-04/schema#\",\"title\":\"cat\",\"properties\":{\"name\":{\"type\":\"string\"},\"age\":{\"type\":\"number\",\"description\":\"Your cat's age in years\"},\"declawed\":{\"type\":\"boolean\"},\"description\":{\"type\":\"string\"}},\"required\":[\"name\",\"age\",\"declawed\"]}";
JsonNode jsonNode = strToJsonNode(json);
JsonNode schemaNode = strToJsonNode(jsonSchema);
System.out.println(JsonSchemaUtil.validate(jsonNode, schemaNode));
Class生产Json schema string
GenerateJsonSchemaUtil.classToJsonSchema(MyClass.class, true)
<=1ms