Search code examples
javapojojsonschema2pojo

JsonSchema2pojo doesnot generate POJO


I was given a pojo like below,

{

"id": "yyy",
"$schema": "http://json-schema.org/draft-04/schema#",
"packages": 
{
    "id": "#/packages",
    "description": "XXX",
    "type": "object",
    "properties": 
    {
        "xx": 
        {
            "description": "Total number of elements in the collection.",
            "type": "integer",
            "minimum": 1,
            "minLength": 1
        }
        ..............
        ...............         
    },
    "additionalProperties": false,
    "required": 
    [
        "xx",
        ...
        ... 
    ]
}
}

When trying to generate POJO with the Jsonschema2POJO I just see the package being created with no class files in it. Even no exceptions occur.

When I add a "properties" around the "packages" tag then it generates the pojo but if any other json references this json i get a "Path not present:packages" error and moreover it makes the schema invalid.

I want to understand if there is any limitation with the tool on the schema version? Or is there any modifications that has to be done in the jsons provided to make it work with the tool. Please suggest.


Solution

  • Answering myself with something that worked for me, schema is hidden inside packages, it cannot be seen by jsonschema2pojo. To use this schema, either put it at the root of the file use a $ref to point to it from somewhere else (like "$ref":"#/packages".

    Click https://github.com/joelittlejohn/jsonschema2pojo/issues/366 for further reference.