187.4. Example
假设我们有以下 JSON 架构
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")