While using Spring Data Rest after migrating an app to Spring Boot, I have observed that entity properties with @Id are no longer marshalled to JSON

前端 未结 5 1685
逝去的感伤
逝去的感伤 2020-11-28 12:03

This question is related to this SO question (Spring boot @ResponseBody doesn't serialize entity id). I have observed that after migrating an app to Spring Boot and usi

5条回答
  •  醉梦人生
    2020-11-28 12:38

    @Id annotation in your model class does the magic.

    public class Location {
    
        @Id
        private String woeid;
        private String locationName;
    

    Then your mongo object will look like this:

    {
        "_id" : "2487889",
        "_class" : "com.agilisys.weatherdashboard.Location",
        "locationName" : "San Diego, CA"
    }
    

提交回复
热议问题