0

Given this JSON:

{ 
    "company": "Big Inc."
    "products": [
        {
            "category": "",
            "daily_sales": {
                "2013-04-13": 23
                "2013-05-27": 67
                "2013-05-28": 89
            }
        },
        {
            "category": "",
            "daily_sales": {
                "2013-04-13": 23
                "2013-05-27": 67
                "2013-05-28": 89
            }
        },
        ...
    ]
}

I want to flatten it and save it in objects like this:

  • SALE
    • company (string)
    • category (string)
    • date (date)
    • sales (int)

So the JSON example above would generate 6 objects.

How do I configure the mapping in RestKit to include the key (the date) as a mapped value into the new object?

thejaz
  • 2,763
  • 2
  • 26
  • 40
  • A single object to hold those parts? You can't, because the JSON holds an array, how would you map all the array contents to a single object? Or am I misunderstanding your question? – Wain May 30 '13 at 06:50
  • I want to save it de-normalized and one object for each date - "So the JSON example above would generate 6 objects." – thejaz May 30 '13 at 10:12
  • RestKit can't do that for you automatically I think. You'd need to either manipulate the data before it is mapped or map the data into another object and then post-process it. – Wain May 30 '13 at 10:16
  • Maybe you're right. But it doesn't seem to be a nice way to hook into the mapping chain when using RKObjectManager. You need a RKObjectRequestOperation to be able to set the `willMapDeserializedResponseBlock` block. I guess I need to copy the `getObjectsAtPathForRelationship...` and `getObjectsAtPathForRouteNamed` methods in RKObjectManager to set that block. – thejaz May 30 '13 at 10:34

1 Answers1

0

It is not possible to do this with RestKit mapping (as of 0.20.1).

You can modify the response to make it RestKit-friendly. I've made a category on RKObjectManager to easily provide a block to modify the response:

https://gist.github.com/gunnarblom/5677324

thejaz
  • 2,763
  • 2
  • 26
  • 40