We use crnk framework for json-api implementation. There is a response body for GET/request body for PATCH:
{
"data": {
"id": "1",
"type": "v1/indicator-data",
"attributes": {
"indicatorValues": [
{
"time": "2018-03-25T00:00:00Z",
"indicator1": 50
},
{
"time": "2018-03-26T00:00:00Z",
"indicator1": 50
}
]
}
}
}
But depending on some external flag the body and returned indicator may be slightly different:
{
"data": {
"id": "2",
"type": "v1/indicator-data",
"attributes": {
"indicatorValues": [
{
"time": "2018-03-25T00:00:00Z",
"indicator2": 15
},
{
"time": "2018-03-26T00:00:00Z",
"indicator2": 15
}
]
}
}
}
In order to achieve this I created the following hierarchy:
@JsonApiResource(type = "v1/indicator-data")
public class IndicatorDataDTO {
@JsonApiId
private int id;
private List<IndicatorTimeEntry> indicatorValues;
}
public class IndicatorTimeEntry {
private ZonedDateTime time;
}
public class Indicator1TimeEntry extends IndicatorTimeEntry {
private Double indicator1;
}
public class Indicator2TimeEntry extends IndicatorTimeEntry {
private Double indicator2;
}
In case @JsonInclude was supported, there would be just 1 TimeEntry class with all the indicator fields in it and all unnecessary indicator values would be set to null.
But as it's not, the above approach was tried, where one of the necessary implementations is manually set in the mapper.
So far it works well for GET method, while during PATCH the body is automatically mapped by crnk to IndicatorTimeEntry and indicator1/2 values are lost. Is it possible to extend/perform manual mapping from json to necessary dto child calss? Or maybe another approach could be tried?