kamikat / moshi-jsonapi

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

How can I parse Metadata. #90

Closed afinas-wii closed 5 years ago

afinas-wii commented 5 years ago

I am trying to parse metadata from a JosnApi for accessing fields inside "meta":{...}. What I'm getting is a JsonBuffer and I don't know how to parse data with this.

Thank you.

kamikat commented 5 years ago

You can parse meta attribute by implementing a JsonAdapter as is mentioned here. And use JsonBuffer.get(JsonAdapter) for deserialization and JsonBuffer.create(JsonAdapter, Object) for serialization.

afinas-wii commented 5 years ago

Thanks for your response. But I'm still facing the issue, This is my meta object, And how can I parse this.

"meta": {
"totalPages": 11,
"nextPage": 2,
"pageSize": 10
}
kamikat commented 5 years ago

Create a new class for your metadata and create a JsonAdapter from it as which is demonstrated by the moshi example.

Then,

You can parse meta attribute by implementing a JsonAdapter as is mentioned here. And use JsonBuffer.get(JsonAdapter) for deserialization and JsonBuffer.create(JsonAdapter, Object) for serialization.