Java 如何使用Spring Boot使用JSON对象数组?
关于本指南: 该指南展示了如何使用RESTful web服务 REST API查询的响应产生以下JSON:Java 如何使用Spring Boot使用JSON对象数组?,java,json,spring-boot,Java,Json,Spring Boot,关于本指南: 该指南展示了如何使用RESTful web服务 REST API查询的响应产生以下JSON: { type: "success", value: { id: 10, quote: "Really loving Spring Boot, makes stand alone Spring apps easy." } } 它创建一个名为Quote.java的域类来包含响应中的数据: package hello; import com.fas
{
type: "success",
value: {
id: 10,
quote: "Really loving Spring Boot, makes stand alone Spring apps easy."
}
}
它创建一个名为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 +
'}';
}
}
我的问题是如何表示以下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
}
像size
和limit
这样的外部对象很简单,但我不知道如何表示值
对象,它看起来像一个json对象数组。这应该可以用
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
}
类输出{
私有字符串大小,
私有整数限制;
私有布尔isLastPage,
私有列表值;
私人int启动;
}
阶级价值
{
用户,
私有字符串权限;
}
类用户{
私有字符串名,
专用字符串电子邮件地址,
私有int-id,
私有字符串displayName,
私有布尔活动,
私有字符串段塞,
私有字符串类型
}
这应该行得通
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
}
类输出{
私有字符串大小,
私有整数限制;
私有布尔isLastPage,
私有列表值;
私人int启动;
}
阶级价值
{
用户,
私有字符串权限;
}
类用户{
私有字符串名,
专用字符串电子邮件地址,
私有int-id,
私有字符串displayName,
私有布尔活动,
私有字符串段塞,
私有字符串类型
}
我们如何将数据(问题中的ex:sample json)插入此类?我们如何将数据(问题中的ex:sample json)插入此类?