Cannot generate pojo from Json Schema Schema

720 views
Skip to first unread message

Steve Owens

unread,
Feb 13, 2014, 7:50:58 PM2/13/14
to jsonschema...@googlegroups.com
I tried running the  pojo generation process on the actual Json schema schema, but it fails due to an attempt to create the same property twice.  It would seem that we should be able to consume the json schema that defines json schemas and make a pojo from it.

{
    "$schema": "http://json-schema.org/draft-03/schema#",
    "id": "http://json-schema.org/draft-03/schema#",
    "type": "object",
   
    "properties": {
        "type": {
            "type": [ "string", "array" ],
            "items": {
                "type": [ "string", { "$ref": "#" } ]
            },
            "uniqueItems": true,
            "default": "any"
        },
       
        "properties": {
            "type": "object",
            "additionalProperties": { "$ref": "#" },
            "default": {}
        },
       
        "patternProperties": {
            "type": "object",
            "additionalProperties": { "$ref": "#" },
            "default": {}
        },
       
        "additionalProperties": {
            "type": [ { "$ref": "#" }, "boolean" ],
            "default": {}
        },
       
        "items": {
            "type": [ { "$ref": "#" }, "array" ],
            "items": { "$ref": "#" },
            "default": {}
        },
       
        "additionalItems": {
            "type": [ { "$ref": "#" }, "boolean" ],
            "default": {}
        },
       
        "required": {
            "type": "boolean",
            "default": false
        },
       
        "dependencies": {
            "type": "object",
            "additionalProperties": {
                "type": [ "string", "array", { "$ref": "#" } ],
                "items": {
                    "type": "string"
                }
            },
            "default": {}
        },
       
        "minimum": {
            "type": "number"
        },
       
        "maximum": {
            "type": "number"
        },
       
        "exclusiveMinimum": {
            "type": "boolean",
            "default": false
        },
       
        "exclusiveMaximum": {
            "type": "boolean",
            "default": false
        },
       
        "minItems": {
            "type": "integer",
            "minimum": 0,
            "default": 0
        },
       
        "maxItems": {
            "type": "integer",
            "minimum": 0
        },
       
        "uniqueItems": {
            "type": "boolean",
            "default": false
        },
       
        "pattern": {
            "type": "string",
            "format": "regex"
        },
       
        "minLength": {
            "type": "integer",
            "minimum": 0,
            "default": 0
        },
       
        "maxLength": {
            "type": "integer"
        },
       
        "enum": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true
        },
       
        "default": {
            "type": "any"
        },
       
        "title": {
            "type": "string"
        },
       
        "description": {
            "type": "string"
        },
       
        "format": {
            "type": "string"
        },
       
        "divisibleBy": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true,
            "default": 1
        },
       
        "disallow": {
            "type": [ "string", "array" ],
            "items": {
                "type": [ "string", { "$ref": "#" } ]
            },
            "uniqueItems": true
        },
       
        "extends": {
            "type": [ { "$ref": "#" }, "array" ],
            "items": { "$ref": "#" },
            "default": {}
        },
       
        "id": {
            "type": "string",
            "format": "uri"
        },
       
        "$ref": {
            "type": "string",
            "format": "uri"
        },
       
        "$schema": {
            "type": "string",
            "format": "uri"
        }
    },
   
    "dependencies": {
        "exclusiveMinimum": "minimum",
        "exclusiveMaximum": "maximum"
    },
   
    "default": {}
}

Joe Littlejohn

unread,
Feb 14, 2014, 3:42:29 PM2/14/14
to jsonschema...@googlegroups.com
The json schema definition depends on the dynamic characteristics of json to create recursive definitions using union types. It's not at all amenable to data-binding to a static type system like Java's. 

The goal of jsonschema2pojo isn't to provide exhaustive coverage of json schemas or json data, it's to provide help wherever you're using a data definition that's amenable to data binding. When working with data that has a highly flexible structure, a more dynamic approach (like using Jackson's tree API) is preferable and data binding is probably a bad choice. So there are plenty of json schemas that aren't compatible with jsonschema2pojo, but I think attempting to adapt the library to accommodate all schemas is not possible (or at least highly impractical) given the constraints of Java.



--
You received this message because you are subscribed to the Google Groups "jsonschema2pojo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages