我在弹簧靴和hateoas下面休息api。
@ResponseBody
public HttpEntity<Resources<StudentDTO>> getStudents(){
// mock data
List<StudentDTO> sl = new ArrayList<StudentDTO>();
StudentDTOss = new StudentDTO();
ss.setAssignmentId("v");
ss.setDescription("d");
Doc d = new Doc();
List<Doc> dl = new ArrayList<Doc>();
dl.add(d);
d.setDocId("docid");
d.setTitle("doc title");
ss.setDoc(dl);
Media m = new Media();
m.setMediaId("mm");
m.setDescription("d");
List<Media> ml = new ArrayList<Media>();
ml.add(m);
ss.setMedia(ml);
sl.add(ss);
List<StudentDTO> result = sl;
Resources<StudentDTO> resources = new Resources<StudentDTO> (result);
resources.add(this.entityLinks.linkToCollectionResource(StudentDTO.class));
return new ResponseEntity<Resources<StudentDTO>>(resources, HttpStatus.OK);
}
我的StudentDTO在下面显示getter / setter,
public class StudentDTO {
@JsonProperty("title")
private String title;
@JsonProperty("doc")
private List<Doc> doc= new ArrayList<Doc>();
@JsonProperty("media")
private List<Media> media= new ArrayList<Media>();
}
Doc域类如下所示,使用getter / setter,
@Document(collection = "document")
public class Doc extends ResourceSupport implements Serializable, Cloneable {
@JsonCreator
public Doc(){}
@Id
@JsonProperty("docId")
String docId;
@JsonProperty("title")
Sting title;
}
响应:
{
"_embedded": {
"studentSubmissions": [
{
"assignmentId": "v",
"description": "d",
"media": [
{
"mediaId": "mm",
"description": "d"
}
],
"doc": [
{
"title": "doc title"
}
]
}
]
},
当我在return语句中检查资源变量时,我可以看到docId,但为什么它在响应中缺失?