Spring Data Pagination returns no results with JSONView

后端 未结 6 1535
广开言路
广开言路 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:50

    If you are using spring-boot, then another simpler solution would be add the following to application.yml

    spring:
      jackson:
        mapper:
          DEFAULT_VIEW_INCLUSION: true
    

    or application.properties

    spring.jackson.mapper.DEFAULT_VIEW_INCLUSION=true
    

    With this approach, we have the advantage of retaining the ObjectMapper managed by Spring Container and not creating a new ObjectMapper. So once we use the spring managed ObjectMapper, then any Custom Serialzers we define will still continue to work e.g CustomDateSerialzer

    Reference: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.html

提交回复
热议问题