目标: 想要为以下 JSON 创建 Json 请求正文:
[
{
"text": "Hey There, its me!"
}
]
尝试过的解决方法:
public class JsonBodyInsideTheArray {
private final String Text;
@JsonCreator
public JsonBodyInsideTheArray (@JsonProperty("Text") String Text) {
this.Text = Text;
}
public String getText() {
return Text;
}
}
数组外:
public class JsonBodyAboveTheArray {
private List<JsonBodyInsideTheArray> requests;
@JsonCreator
public JsonBodyAboveTheArray (@JsonProperty("") List<JsonBodyInsideTheArray > requests) {
this.requests = requests;
}
public List<JsonBodyInsideTheArray > getRequests() {
return requests;
}
}
使用上面的代码,会检索到以下 JSON,这不是预期的: `
{
"requests": [
{
"text": "Hey There, its me!"
}
]
}
`
List<JsonBodyInsideTheArray>
是你期望的输出