Hi,
Apologies if this is a duplicate, but I've poked around a bit and couldn't find an answer to my question anywhere.
I have two projects that are part of a multiple project build, e.g. ClientProject and ServiceProject.
In the client project, I'm generating a POJO, e.g. ClientPojo.java.
In the service project, I'm generating a POJO, e.g. ServicePojo.java, that I would like to extend ClientPojo.java.
The client project is configured with a dependency on the client project, e.g.:
dependencies{
compile project(':ClientProject')
}
My preference is to have the JSON schema for ServicePojo contain a reference to the ClientProject JSON schema, e.g.:
{
"type": "object",
"extends": {
"$ref": "<what do i put here?>/ClientPojo.json"
},
"additionalProperties": false,
"properties": {
"newproperty1": { "type": "number" },
"newproperty2": { "type": "string" },
"newproperty3": { "type": "string" },
"newproperty4": { "type": "string" }
}
}
However, I had a hard time getting the generator to discover the parent schema. At first, I tried setting "$ref" to "classpath:" and "resource:", but didn't have any luck.
I was finally successful in getting the parent schema file discovered by adding the client projects JSON schema resources to the service projects source dirs, e.g.:
sourceSets {
main {
resources {
srcDir "../ClientProject/src/main/resources/jsonmodel"
}
}
}
and then modifying the "$ref" in the ClientPojo.json to use relative pathing to find the parent JSON schema file:
{
"type": "object",
"extends": {
"$ref": "../ClientPojo.json"
},
"additionalProperties": false,
"properties": {
"newproperty1": { "type": "number" },
"newproperty2": { "type": "string" },
"newproperty3": { "type": "string" },
"newproperty4": { "type": "string" }
}
}
With this approach, the ServicePojo.java generated successfully. However, another class called ServicePojoParent.java was also generated, and the ServicePojo.java class extends this ServicePojoParent.java class, rather than generated Java class in the Client project.
It may be simpler if I can just specify the specific Java class that I would like the generated ServicePojo.java to extend. However, I wasn't able to find clear documentation on how to do this, so I'm not sure if it's possible.
Does anyone have any thoughts?
Thanks,
Tony