0

I have below rest api with spring boot and hateoas.

    @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);

    }

My StudentDTO looks below with getters/setters,

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 domain class looks like below with getters/setters,

@Document(collection = "document")
public class Doc extends ResourceSupport implements Serializable, Cloneable {    
        @JsonCreator
        public Doc(){}
        @Id
        @JsonProperty("docId")
        String docId;
        @JsonProperty("title")
        Sting title;    
    }

Response:

{
  "_embedded": {
    "studentSubmissions": [
      {
        "assignmentId": "v",
        "description": "d",
        "media": [
          {
            "mediaId": "mm",
            "description": "d"
          }
        ],
        "doc": [
          {
            "title": "doc title"
          }
        ]
      }
    ]
  },

When i inspect resources variable at return statement i can see the docId but why it is missing in the response?

Harshana
  • 7,297
  • 25
  • 99
  • 173
  • To better help you, please provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Andreas May 29 '16 at 21:04
  • i shorten the text – Harshana May 30 '16 at 02:23
  • You show a call to `service.getStudents()` that is not in evidence. *Complete* means to change the code so we can see all the relevant details, e.g. replace that line with code to create a `result` value, so we know the data you're looking at. – Andreas May 30 '16 at 02:29
  • Apparently it has nothing to do with the service call. I have mock the data and test it. Pls see the updated question – Harshana May 30 '16 at 03:05
  • thanks Andreas. it helps – Harshana May 30 '16 at 05:39

0 Answers0