186.4. 예제
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의 유효성을 검사할 수 있습니다. 여기서 classpath에서 myschema.json 이 로드됩니다.
from("direct:start")
.to("json-validator:myschema.json")
.to("mock:end")