I want to create a series of custom POJO's in Java 8 to represent a data structure received and deserialised via JSON.
The data looks like (top level down)
RootNode
<Set>LocalDate
<Set>Location
<Set>Shift
Integer
So for example the data might look like:
2021-06-20
AMBULANCE\CA\Los Angeles
Morning
4
Afternoon
5
Nights
5
AMBULANCE\CA\San Deigo
Afternoon
7
Nights
6
Morning
4
2021-06-21
AMBULANCE\CA\Los Angeles
Night
6
Morning
5
Afternoon
5
ANBULANCE\CA\San Francisco
Afternoon
5
Morning
4
....
In the above structure each date has several child locations, each location has three child shifts, and each shift has a integer.
To represent this as Java Objects I have created:
public class RootNode {
public RootNode(){}
public LinkedHashMap<LocalDate, Location> locations;
}
public class Location {
public Set<Shift> shifts;
}
public class Shift {
public enum ShiftTypes {
MORNING, AFTERNOON, NIGHT
}
public Integer count;
}
There should be no duplicates of dates or locations or employees.
Do these classes correctly represent the data structure outlined?
All these classes are custom except for LocalDate which is native - I was uncertain whether to create a new custom date class which in turn has a Set attribute?
If this is the correct way to setup the structure what would the syntax be? Using extends?
UPDATE
I tried to extend LocalDate with:
public class ShiftLocalDate extends LocalDate {
public Set<Shift> shifts;
}
But it appears this can't be done since LocalDate is final?