[英]How do I consume an array of JSON objects with Spring Boot?
With reference to this guide: https://spring.io/guides/gs/consuming-rest/ 参考本指南: https : //spring.io/guides/gs/using-rest/
The guide shows how to consume a RESTful web service. 该指南显示了如何使用RESTful Web服务。
The response from the REST API query results in the following JSON: REST API查询的响应将导致以下JSON:
{
type: "success",
value: {
id: 10,
quote: "Really loving Spring Boot, makes stand alone Spring apps easy."
}
}
It creates a domain class called Quote.java to contain the data in the response: 它创建一个称为Quote.java的域类以包含响应中的数据:
package hello;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Quote {
private String type;
private Value value;
public Quote() {
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Value getValue() {
return value;
}
public void setValue(Value value) {
this.value = value;
}
@Override
public String toString() {
return "Quote{" +
"type='" + type + '\'' +
", value=" + value +
'}';
}
}
My questions is how do I represent the following json: 我的问题是如何表示以下json:
{
"size": 1,
"limit": 25,
"isLastPage": true,
"values": [
{
"user": {
"name": "jcitizen",
"emailAddress": "jane@example.com",
"id": 101,
"displayName": "Jane Citizen",
"active": true,
"slug": "jcitizen",
"type": "NORMAL"
},
"permission": "ADMIN"
}
],
"start": 0
}
The outer objects like size
and limit
are straightforward but I can't figure out how to represent the values
object, which looks like an array of json objects. 外部对象(例如
size
和limit
很简单,但是我不知道如何表示values
对象,它看起来像json对象数组。
This should work. 这应该工作。
class Output {
private String size,
private int limit;
private boolean isLastPage,
private List<Value> values;
private int start ;
}
class Value
{
User user,
private String permission;
}
class User {
private String name,
private String emailAddress,
private int id,
private String displayName,
private boolean active,
private String slug,
private String type
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.