javajsonspring-dataspring-data-jpaspring-data-rest

Spring data rest sorting fields with underscores


We are using a very simple setup of @RepositoryRestResource on top of a PagingAndSortingRepository connected to a postgres database. Also we have configured spring.jackson.property-naming-strategy=SNAKE_CASE to return pretty json. It was all fine and dandy until we started sorting. As we have discovered - sorting requires us to provide the actual class field names (which we of course have in camel case):

get("/thing?sort=dateCreated,desc")

And when we try to do javascript friendly

get("/thing?sort=date_created,desc")

it fails miserably because jpa tries to split the parameter by the underscore.

Is there a simple way to have the path params the same format as we have them in the json that we are returning?


Solution

  • There is a bug for this - DATAREST-883. It was fixed and released. But then, due to regressions (DATAREST-909) this has been dropped in the very next release. I asked them on Github if they plan to have this again as this has bitten me in the past as well. We'll see what they have to say about this.

    For now you can:

    The status of the feature in the spring-boot versions I've tested with: