Hi all,

If we are using staxon for json schema processing in data mapper tool as we
are required to validate the json schema being used we will have to either
write our own validator or use a 3rd party jason schema validator library
with modifications.

I evaluated [1] and [2] existing json schema validators from [3]. [1] is a
jackson based validator while [2] is a org.json based validator. since
there is no staxon based validator we will have to parse the JSON twice:
once for the schema validator, and once for our own processing. In a case
like that,  library [2] is probably still a better choice, since it claims
to be 4x faster <https://github.com/erosb/json-schema-perftest> than the
Jackson-based fge library.

We can use this option after evaluating the effort on parsing the schema
twice vs writing our own validator.

[1] https://github.com/fge/json-schema-validator - LGPLv3 license

[2] https://github.com/everit-org/json-schema - Apache 2.0 license

[3] http://json-schema.org/implementations.html

Regards
Awanthika

Awanthika Senarath
Software Engineer, WSO2 Inc.
Mobile: +94717681791



On Mon, Mar 7, 2016 at 10:30 AM, Viraj Rajaguru <[email protected]> wrote:

> Thanks for the comparison.
>
> On Mon, Mar 7, 2016 at 8:51 AM, Awanthika Senarath <[email protected]>
> wrote:
>
>> Hi all,
>>
>> Please find the XSD schema [1] corresponding avro schema [2] and the
>> json-schema [3] generated using the jsonix library at [4].
>>
>> You can observe that the json-schema is way bulkier than the avro schema,
>> yet more flexible and informative as it by default support the namespace
>> and the attribute aspects.
>>
>>
>>
>> [1] XSD schema :
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" 
>> xmlns:xs="http://www.w3.org/2001/XMLSchema";>
>>   <xs:element name="breakfast_menu">
>>     <xs:complexType>
>>       <xs:sequence>
>>         <xs:element name="food" maxOccurs="unbounded" minOccurs="0">
>>           <xs:complexType>
>>             <xs:sequence>
>>               <xs:element type="xs:string" name="name"/>
>>               <xs:element name="price" minOccurs="0">
>>                 <xs:complexType>
>>                   <xs:sequence>
>>                     <xs:element type="xs:string" name="usd"/>
>>                     <xs:element type="xs:string" name="lkr" minOccurs="0"/>
>>                   </xs:sequence>
>>                 </xs:complexType>
>>               </xs:element>
>>               <xs:element type="xs:string" name="description"/>
>>               <xs:element type="xs:string" name="calories"/>
>>             </xs:sequence>
>>           </xs:complexType>
>>         </xs:element>
>>       </xs:sequence>
>>     </xs:complexType>
>>   </xs:element>
>> </xs:schema>
>>
>>
>> [2] Corresponding Avro schema :
>>
>> {
>>   "name" : "BreakfastMenu",
>>   "namespace" : "my.generated.avro",
>>   "type" : "record",
>>   "fields" : [ {
>>     "name" : "food",
>>     "type" : [ "null", {
>>       "type" : "array",
>>       "items" : {
>>   "name" : "BreakfastMenuFood",
>>   "namespace" : "my.generated.avro",
>>   "type" : "record",
>>   "fields" : [ {
>>     "name" : "name",
>>     "type" : "string",
>>     "default" : ""
>>   }, {
>>     "name" : "price",
>>     "type" : {
>>   "name" : "BreakfastMenuFoodPrice",
>>   "namespace" : "my.generated.avro",
>>   "type" : "record",
>>   "fields" : [ {
>>     "name" : "usd",
>>     "type" : "string",
>>     "default" : ""
>>   }, {
>>     "name" : "lkr",
>>     "type" : "string",
>>     "default" : ""
>>   } ]
>> }
>>   }, {
>>     "name" : "description",
>>     "type" : "string",
>>     "default" : ""
>>   }, {
>>     "name" : "calories",
>>     "type" : "string",
>>     "default" : ""
>>   } ]
>> }
>>     } ],
>>     "default" : "null"
>>   } ]
>> }
>>
>> [3] Corresponding Json-schema :
>>
>> {
>>     "id":"#",
>>     "definitions":{
>>         "BreakfastMenu.Food":{
>>             "type":"object",
>>             "title":"BreakfastMenu.Food",
>>             "required":[
>>                 "name",
>>                 "description",
>>                 "calories"
>>             ],
>>             "properties":{
>>                 "name":{
>>                     "title":"name",
>>                     "allOf":[
>>                         {
>>                             
>> "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/string";
>>                         }
>>                     ],
>>                     "propertyType":"element",
>>                     "elementName":{
>>                         "localPart":"name",
>>                         "namespaceURI":""
>>                     }
>>                 },
>>                 "price":{
>>                     "title":"price",
>>                     "allOf":[
>>                         {
>>                             "$ref":"#/definitions/BreakfastMenu.Food.Price"
>>                         }
>>                     ],
>>                     "propertyType":"element",
>>                     "elementName":{
>>                         "localPart":"price",
>>                         "namespaceURI":""
>>                     }
>>                 },
>>                 "description":{
>>                     "title":"description",
>>                     "allOf":[
>>                         {
>>                             
>> "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/string";
>>                         }
>>                     ],
>>                     "propertyType":"element",
>>                     "elementName":{
>>                         "localPart":"description",
>>                         "namespaceURI":""
>>                     }
>>                 },
>>                 "calories":{
>>                     "title":"calories",
>>                     "allOf":[
>>                         {
>>                             
>> "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/string";
>>                         }
>>                     ],
>>                     "propertyType":"element",
>>                     "elementName":{
>>                         "localPart":"calories",
>>                         "namespaceURI":""
>>                     }
>>                 }
>>             },
>>             "typeType":"classInfo",
>>             "propertiesOrder":[
>>                 "name",
>>                 "price",
>>                 "description",
>>                 "calories"
>>             ]
>>         },
>>         "BreakfastMenu.Food.Price":{
>>             "type":"object",
>>             "title":"BreakfastMenu.Food.Price",
>>             "required":[
>>                 "usd"
>>             ],
>>             "properties":{
>>                 "usd":{
>>                     "title":"usd",
>>                     "allOf":[
>>                         {
>>                             
>> "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/string";
>>                         }
>>                     ],
>>                     "propertyType":"element",
>>                     "elementName":{
>>                         "localPart":"usd",
>>                         "namespaceURI":""
>>                     }
>>                 },
>>                 "lkr":{
>>                     "title":"lkr",
>>                     "allOf":[
>>                         {
>>                             
>> "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/string";
>>                         }
>>                     ],
>>                     "propertyType":"element",
>>                     "elementName":{
>>                         "localPart":"lkr",
>>                         "namespaceURI":""
>>                     }
>>                 }
>>             },
>>             "typeType":"classInfo",
>>             "propertiesOrder":[
>>                 "usd",
>>                 "lkr"
>>             ]
>>         },
>>         "BreakfastMenu":{
>>             "type":"object",
>>             "title":"BreakfastMenu",
>>             "properties":{
>>                 "food":{
>>                     "title":"food",
>>                     "allOf":[
>>                         {
>>                             "type":"array",
>>                             "items":{
>>                                 "$ref":"#/definitions/BreakfastMenu.Food"
>>                             },
>>                             "minItems":0
>>                         }
>>                     ],
>>                     "propertyType":"element",
>>                     "elementName":{
>>                         "localPart":"food",
>>                         "namespaceURI":""
>>                     }
>>                 }
>>             },
>>             "typeType":"classInfo",
>>             "propertiesOrder":[
>>                 "food"
>>             ]
>>         }
>>     },
>>     "anyOf":[
>>         {
>>             "type":"object",
>>             "properties":{
>>                 "name":{
>>                     "allOf":[
>>                         {
>>                             
>> "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/QName";
>>                         },
>>                         {
>>                             "type":"object",
>>                             "properties":{
>>                                 "localPart":{
>>                                     "enum":[
>>                                         "breakfast_menu"
>>                                     ]
>>                                 },
>>                                 "namespaceURI":{
>>                                     "enum":[
>>                                         ""
>>                                     ]
>>                                 }
>>                             }
>>                         }
>>                     ]
>>                 },
>>                 "value":{
>>                     "$ref":"#/definitions/BreakfastMenu"
>>                 }
>>             },
>>             "elementName":{
>>                 "localPart":"breakfast_menu",
>>                 "namespaceURI":""
>>             }
>>         }
>>     ]
>> }
>>
>> [4]
>> https://github.com/highsource/jsonix-schema-compiler/wiki/JSON-Schema-Generation
>>
>> Regards
>> Awanthika Senarath
>> Software Engineer, WSO2 Inc.
>> Mobile: +94717681791
>>
>>
>>
>
>
> --
> Viraj Rajaguru
> Senior Software Engineer
> WSO2 Inc. : http://wso2.com
>
> Mobile: +94 77 3683068
>
>
>
>
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture

Reply via email to