mutualmobile/MMRecord

Manually Deserialize JSON

Closed this issue · 2 comments

Conrad, we're making good use of MMRecord to easily turn our GET responses into core data objects. Great stuff. On occasion, our POST and PUT api's also return objects that we would like to deserialize into Core Data objects. Apart from creating a separate MMServer for each operation type, is there a way we can just "manually" ask MMRecord to deserialize the JSON blobs returned via AFNetworking? Thanks, -alex

Hey Alex,

Thats a good question. There are a few ways of doing this, but admittedly I think the library could support a more streamlined workflow.

One option is to manually use the MMRecordResponse class itself to do whatever you want. This class is basically the entry point to the MMRecord parsing system. However, that class has no concept of how to make requests, and also doesn't have much notion of Core Data threading concerns. You could use this if you want to (following the example laid out in the AFMMRecordResponseSerializer extension class), but I'm not sure its what I would recommend.

Another option would be to build your own MMServer subclass that fits more specifically to the way your app works. That server would know how to make GET/POST/PUT requests based on some knowledge of the API you're working with. Personally, I think this is probably the route that I would go. But, I don't know much about the API you're working with, so take my advice with a grain of salt.

Regarding the MMRecordResponse class, I am planning to make a few updates to this class for MMRecord 2.0...likely making it a block-based class, and possibly incorporating some of the Core Data threading logic there too. This might make that class a bit more digestible for this sort of use-case. However, I don't have any kind of date in mind on when that might be available.

Thanks,

  • Conrad

Hey Conrad, thanks again for the feedback. I'll look at both of those options. -a