kamikat / moshi-jsonapi

JSON API v1.0 Specification in Moshi.
MIT License
156 stars 34 forks source link

Paged requests #74

Open Pedroalexandrelopes opened 6 years ago

Pedroalexandrelopes commented 6 years ago

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?

kamikat commented 6 years ago

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.

sterien7 commented 2 years ago

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