Results 1 to 2 of 2

Thread: Data JPA [PageRequest] object JSON String can't revert!

  1. #1
    Join Date
    Mar 2012
    Posts
    3

    Exclamation Data JPA [PageRequest] object JSON String can't revert!

    Code:
    		PageRequest page = new PageRequest(0, PAGE_SIZE, new Sort(
    				Sort.Direction.DESC, "date"));
    		Page<User> users = this.dao.findAll(page);
    
    		ObjectMapper mapper = new ObjectMapper();
    		
    		ByteArrayOutputStream out = new ByteArrayOutputStream();
    		mapper.writeValue(out, page);
    		
    		String json = new String(out.toByteArray());
    		
    		page = mapper.readValue(json, PageRequest.class);
    Exception message:
    org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class org.springframework.data.domain.PageRequest]: can not instantiate from JSON object (need to add/enable type information?)......

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    It (by default) requires a default no-args constructor which isn't available for the PageRequest class. You should be able to override this by creating your json serializer.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •