Spring Data Pagination returns no results with JSONView

后端 未结 6 1532
广开言路
广开言路 2021-02-06 02:53

I am using Spring data pagination in my REST Controller and returning Paged entity. I would like to control the data returned as JSON with the help of JSONViews.

I am a

6条回答
  •  野性不改
    2021-02-06 03:49

    you need to add annotation @JsonView(TravelRequestView.MyRequests.class) recursively. Add it to the field you want to see in Page class.

    public class Page {
        @JsonView(TravelRequestView.MyRequests.class)
        private T view;
     ...
    }
    

    or enable DEFAULT_VIEW_INCLUSION for ObjectMapper:

    
        
            
            
                
                    
                        
                    
                
            
        
    
    

    or use dto objects for your responses where you can control all your views

提交回复
热议问题