Search code examples
javajsonjsonschemajsonschema2pojo

Generate Multiple POJO's from single json schema file


I am using jsonschema2pojo to generate POJO's. Its working fine. But I want to generate multiple POJO's from single json schema file. Is this possible using jsonschema2pojo plugin.

One way to generate multiple POJO's is to provide multiple json schema files, but i don't want to do that. I want to provide only one json schema file as input.

I am providing following json schema as input:

{
  "Address": {
    "description": "AnAddressfollowingtheconventionofhttp: //microformats.org/wiki/hcard",
    "type": "object",
    "properties": {
        "post-office-box": {
            "type": "string"
        },
        "post-office-address": {
            "type": "string"
        }
    },
    "additionalProperties": false
  },
  "AddressDetails": {
    "description": "AnAddressDetailsfollowingtheconventionofhttp: //microformats.org/wiki/hcard",
    "type": "object",
    "properties": {
        "post-office-box": {
            "type": "string"
        },
        "post-office-address": {
            "type": "string"
        }
    }
  }
}

Above schema is valid schema but nothing gets created. I don't know If I am missing something or its just not possible using jsonschema2pojo.

Also is there a way to generate these entities at run-time?

If anyone has any thoughts on the same, do share.


Solution

  • The solution was to split these into separate files, or reference these schemas from another file like:

    {"$ref" : "schemas/myfile.json#AddressDetails"}
    

    Thanx.