2016-06-03 8 views
0

Ich versuche Validate JSON-Schema-Komponente in Mule-Flow zu verwenden, und ich bekomme com.fasterxml.jackson.core.JsonParseException für das JSON, das übergeben wird. Unten ist das JSON-Schema, JSON-Beispiel und Code des Mule-Flusses. Kannst du mir bitte zeigen, wo ich Fehler mache?Mule JSON-Schema-Validierung

Json Schema:

{ 
    "$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 gebene Methode POST:

[ 
    { 
     "id": 2, 
     "name": "An ice sculpture", 
     "price": 12.50, 
    }, 

    { 
     "id": 3, 
     "name": "A blue mouse", 
     "price": 25.50, 
    } 
] 

Fehler:

Root Exception stack trace: 
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name 
at [Source: [email protected]; 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) 

Mule Fluss:

<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

Muleflow fein : user6284034

Antwort

0

Es gibt nur wenige Fehler sowohl in der JSON und das Schema wie folgt: -
Es gibt ein zusätzliches Komma , nach "price": 12.50
Also das Valid JSON werden sein: -

[ 
    { 
     "id": 2, 
     "name": "An ice sculpture", 
     "price": 12.50 
    }, 

    { 
     "id": 3, 
     "name": "A blue mouse", 
     "price": 25.50 
    } 
] 

In JSON-Schemadatei jsonschema.json Es gibt zwei Fehler: -
Sie müssen "type": "array" statt "type": "object"
01 setzenund nächste ist "exclusiveMinimum": true scheint mit diesem JSON Eingang ungültig zu sein ...
Also, das korrekte Schema Arbeits JSON sein wird: -

{ 
    "$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"] 
} 

Try it .. es funktioniert :)

+0

Danke @ Anirban-sen-chowdhary ...... es arbeitete mit der Haltung "exclusiveMinimum": auch wahr. – user6284034

0

Der JSON-Pass ist nicht korrekt. Es hat ein zusätzliches Komma ',' nach dem Preis: 12,50. Auch nach dem zweiten Preiselement wird ein zusätzliches Komma hinzugefügt. Entfernen Sie es einfach und es funktioniert gut.

+0

Dank @tortoise. – user6284034