[英]Accepting different types of JSON array input?
I have a JAX-RS/Jersey project where I'd like to make things easier for my clients. 我有一个JAX-RS / Jersey项目,在这里我想为客户简化事情。
Currently a POST body to a service is like this: 当前,服务的POST正文是这样的:
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? 我将如何为每个数组建模以获取正确的输入?
Create a POJO 创建一个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. 在其他领域也做同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.