Create a POJO
public class PiecePie {
private Long piePieceId;
// getters and setters
}
and use a
private List<PiecePie> piePieceIds;
Do the same thing for the other field.
Question
I have a JAX-RS/Jersey project where I'd like to make things easier for my clients.
Currently a POST body to a service is like this:
POST http://localhost:7101/account/2274321/pieces/
{
"piePieceIds": [
1
],
"cakePieceIds": [
2
],
"splitName": "Split"
}
I can map the arrays to an input object using
private List<Long> piePieceIds;
private List<Long> cakePieceIds;
This works fine. However, a client has asked for a change to make her life easier:
POST http://localhost:7101/account/2274321/pieces/
{
"piePieceIds": [
{
"piePieceId": 1
}
],
"cakePieceIds": [
{
"cakePieceId": 2
}
],
"splitName": "Split"
}
How would I model each array to get the correct input?
Solution
Create a POJO
public class PiecePie {
private Long piePieceId;
// getters and setters
}
and use a
private List<PiecePie> piePieceIds;
Do the same thing for the other field.