Can we achieve hierarchical inheritence in java, I've a scenario something like this
class Person {
String name;
int age;
List<Address> addressList;
// ... getters, setters
}
class Address {
String state;
String contry;
// ... getters, setters
}
class ExtendedAddress extends Address {
String street;
// ... getters, setters
}
class ExtendedPerson extends Person {
String occupation;
List<ExtendedAddress> addressList;
// ... getters, setters
}
But in the ExtebdedPerson class, the getters and setters give errors as their return type changes..
here either I need to change the name of addressList or manually write setter and getter logic.
I'll not be able to because these DTOs are generated by swagger..
Is there an approach I can follow here? Or, Is there a way I can write my swagger yaml more effectively.
This is my swagger definition
Person:
type: object
properties:
name:
type: string
description: "Name of the person"
age:
type: integer
description: "Age of the person"
addressList:
type: array
description: "Address List"
items:
$ref: '#/definitions/Address'
Address:
type: object
properties:
state:
type: string
description: "Name of the state"
country:
type: string
description: "Name of the country"
ExtendedAddress:
allOf:
- $ref: '#/definitions/Address'
- type: object
type: object
properties:
street:
type: string
description: "Name of the street"
ExtendedPerson:
allOf:
- $ref: '#/definitions/Person'
type: object
properties:
occupation:
type: string
description: "Name of the occupation"
addressList:
type: array
description: "Address List"
items:
$ref: '#/definitions/ExtendedAddress'