What is the correct way to execute a Retrofit call that returns a byte[]?


I am trying to call a method using Retrofit that returns a PDF as a byte[] wrapped in a Spring ResponseEntity. Method basically just looks like this:

@Headers("Content-Type: application/pdf")
Call<ResponseEntity<byte[]>> getPdf(
   @Query("number") final String number

It seems like jackson has no idea how to deserialize this byte array, and upon usage:

final ResponseEntity<byte[]> pdf = service.getPdf(number).execute().body();

I get the following error:

Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.springframework.http.ResponseEntity` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

How should I be leveraging the client method to retrieve the ResponseEntity?


Ended up changing the implementation of the service method to return a Spring Resource instead of a byte array directly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at


Login to comment