Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring data Page/Pageable can't deserialization,how to use?

if use Page/Pageable in controller with rest, I got error,because they hasn't empty construct for deserialization

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of org.springframework.data.domain.Page, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
 at [Source: java.io.PushbackInputStream@67635da8; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148) ~[jackson-databind-2.6.4.jar:2.6.4]
at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:892) ~[jackson-databind-2.6.4.jar:2.6.4]
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:139) ~[jackson-databind-2.6.4.jar:2.6.4]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3736) ~[jackson-databind-2.6.4.jar:2.6.4]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2810) ~[jackson-databind-2.6.4.jar:2.6.4]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:221) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 30 common frames omitted
like image 661
Dreampie Avatar asked Jan 25 '16 02:01

Dreampie


Video Answer


1 Answers

The Pageable implementation Page is not a pure POJO that Jackson expects. However, you can build you own implementation of Pageable. You'll be able to pass down that implementation of yours to Spring Data since it will respect the Pageable contract.

I had you problem and came around by implementing Pageable myself so my Java Rest Client could exchange with my Spring Data Jpa Server.

like image 111
Daniel Lavoie Avatar answered Sep 21 '22 06:09

Daniel Lavoie