I have this requirement of fetching data from database based on id. This record can have multiple values for same id and type since it is of type history. The versions however that we use change everytime. Sample of what I want and what I am getting are as below. I am using Java8
, rest-api
and json api
where I mark relationship attributes with annotations. This data is saved and fetched from database, so to be entirely unique row, the id and version combination should be unique. Which means records with same id present in database but with different versions
What I want:
{
"data":{
"id": "123",
"attributes":{
"name": "SJ"
},
"relationships":{
"contact":{
"data":[
{
"type":"test",
"id":"4567"
},
{
"type":"test",
"id":"4567"
}
]
}
}
},
"included":[
{
"type":"test",
"id":"4567",
"attributes":{
"testfield":"testfield 1",
"version": 0
}
},
{
"type":"test",
"id":"4567",
"attributes":{
"testfield":"testfield 2",
"version":1
}
}
]
}
What I get:
{
"data":{
"id": "123",
"attributes":{
"name": "SJ"
},
"relationships":{
"contact":{
"data":[
{
"type":"test",
"id":"4567"
},
{
"type":"test",
"id":"4567"
}
]
}
}
},
"included":[
{
"type":"test",
"id":"4567",
"attributes":{
"testfield":"testfield 1",
"version":1
}
}
]
}