moshi-jsonapi icon indicating copy to clipboard operation
moshi-jsonapi copied to clipboard

Paged requests

Open Pedroalexandrelopes opened this issue 7 years ago • 2 comments

Hi, I'm using Retrofit to make paged requests. I need to be able to get paging attributes contained in meta.

The retrofit interface has a call like this:

@GET("appointments?include=service") Call<List<Appointment>> getBusinessAppointments(@HeaderMap Map<String, String> headers, @Query("filter[businessId]") String businessId, @QueryMap Map<String, String> options);

When making the call, I receive the Appointments list but no way of getting the attributes of meta. The response has this format:

{"data":[...],"included":[...],"meta":{"page":{"page":1,"total-entries":10,"total-pages":1,"number":2,"size":30}}}

Is there any way of getting the 'total-entries' and 'size' params?

Pedroalexandrelopes avatar Jan 02 '18 18:01 Pedroalexandrelopes

The getMeta() returns a JsonBuffer object (https://github.com/kamikat/moshi-jsonapi#metalinksjsonapi-properties). There you can create a JsonAdapter as is described in https://github.com/square/moshi and pass it to JsonBuffer.get to get the object.

kamikat avatar Feb 08 '18 15:02 kamikat

@kamikat how can you getMeta on the Document rather than each Object? As long as in this example the result is List<Appointment>

sterien7 avatar Sep 09 '22 12:09 sterien7