186.4. 示例
假设我们有以下 JSON Schema
myschema.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {},
"id": "my-schema",
"properties": {
"id": {
"default": 1,
"description": "An explanation about the purpose of this instance.",
"id": "/properties/id",
"title": "The id schema",
"type": "integer"
},
"name": {
"default": "A green door",
"description": "An explanation about the purpose of this instance.",
"id": "/properties/name",
"title": "The name schema",
"type": "string"
},
"price": {
"default": 12.5,
"description": "An explanation about the purpose of this instance.",
"id": "/properties/price",
"title": "The price schema",
"type": "number"
}
},
"required": [
"name",
"id",
"price"
],
"type": "object"
}
我们可以通过以下 Camel 路由验证传入的 JSON,其中 myschema.json 是从 classpath 加载的。
from("direct:start")
.to("json-validator:myschema.json")
.to("mock:end")