返回的Json会自动过滤掉空指针的对象,但是若遇到非空指针的没有任何内容的对象,举例如下:
public class Person {
private String name;
private Integer age;
private Boolean sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Boolean getSex() {
return sex;
}
public void setSex(Boolean sex) {
this.sex = sex;
}
}
public class TestResponse extends DdxBaseResponse {
private Person person;
private List<Person> personList;
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public List<Person> getPersonList() {
return personList;
}
public void setPersonList(List<Person> personList) {
this.personList = personList;
}
}
@RestController
public class TestController {
@Autowired
private ObjectMapper objectMapper;
// @RsaToken
// @Perm(1)
@PostMapping("/test")
public TestResponse go(@Validated @RequestBody TestRequest request) {
TestResponse response = new TestResponse();
return response;
}
}
@RestController
public class TestController {
@Autowired
private ObjectMapper objectMapper;
// @RsaToken
// @Perm(1)
@PostMapping("/test")
public TestResponse go(@Validated @RequestBody TestRequest request) {
TestResponse response = new TestResponse();
response.setPerson(new Person()); //创建下,让其非空指针
response.setPersonList(new ArrayList<>()); //创建下,让其非空指针
return response;
}
}
标签:return,SpringBoot,void,private,public,数组,response,TestResponse,服务端
From: https://www.cnblogs.com/del88/p/17472651.html