Roufid

InvalidDefinitionException: Cannot construct instance of `org.springframework.data.domain.PageImpl` – Solution

Spring

When working with Spring MVC and calling a web service that returns a Page<Something>, you will encounter the error : com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of org.springframework.data.domain.PageImpl (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator). This tutorial will show how to fix it.

Solution

Create a Java class that extends PageImpl having a constructor annotated  @JsonCreator with like below:

And use it like this :

References