سؤال

I am currently working an Android app that receives most of the displayed data from a REST interface.

First, I request the information for a company the request includes a list of store IDs. With each ID I can then request the details for this store.

As part of my app I can update the store opening hours and send them back to the server. For that, I obviously need the store ID to tell the server which store to update.

Now, my question: The JSON object returned by {SERVER}/StoreDetails/{ID} does not include the the store ID. So I need to first fetch the JSON, parse it, and then manually add the store ID to the object - which I feel needlessly complicates my logic, as well as my model objects which now either need a setter of some kind of copy/update constructor when they could otherwise be totally immutable...

Would it be/have been reasonable to include the store ID in the returned JSON object or is that considered redundant and a bad practice?

هل كانت مفيدة؟

المحلول

Sounds perfectly reasonable to me to add the store ID into the payload - as you say, the payload is then more "standalone", and should not need modified after being parsed. Messing with the object to inject a field that you could trivially include when building the response feels wrong to me.

نصائح أخرى

Have a look a this ressource: http://jsonapi.org/format/#document-sigular-resources. When you follow this standard you have to include the id of the store in your json.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى softwareengineering.stackexchange
scroll top