我正在尝试在Mule流中使用Validate JSON模式组件,并且我正在为传递的json获取com.fasterxml.jackson.core.JsonParseException。下面是json模式,json示例和Mule流程的代码。你能指点我在哪里做错了吗?
Json架构:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "integer"
},
"name": {
"description": "Name of the product",
"type": "string"
},
"price": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
}
},
"required": ["id", "name", "price"]
}
Json传递给POST方法:
[
{
"id": 2,
"name": "An ice sculpture",
"price": 12.50,
},
{
"id": 3,
"name": "A blue mouse",
"price": 25.50,
}
]
错误:
Root Exception stack trace:
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name
at [Source: java.io.InputStreamReader@6e7f030; line: 6, column: 5]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1419)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:508)
骡流:
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="jsonschemavalidationFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" allowedMethods="POST" doc:name="HTTP"/>
<json:validate-schema schemaLocation="jsonschema.json" doc:name="Validate JSON Schema"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
答案 0 :(得分:0)
json u r传球不合适。它有一个额外的逗号','价格后:12.50。即使在第二个价格元素之后,也会添加额外的逗号。 只需删除它,它工作正常。
答案 1 :(得分:0)
JSON和Schema中的错误如下: -
在,
之后还有一个额外的逗号"price": 12.50
所以Valid JSON将是: -
[
{
"id": 2,
"name": "An ice sculpture",
"price": 12.50
},
{
"id": 3,
"name": "A blue mouse",
"price": 25.50
}
]
在JSON架构文件中 jsonschema.json 有两个错误: -
您需要输入&#34; type": "array"
而不是"type": "object"
这个JSON输入似乎无效"exclusiveMinimum": true
...
因此,正确的工作JSON模式将是: -
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "array",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "integer"
},
"name": {
"description": "Name of the product",
"type": "string"
},
"price": {
"type": "number",
"minimum": 0
}
},
"required": ["id", "name", "price"]
}
试试吧..它会正常工作:)