0
votes

I have the following JSON:

{
    "votecategory": [
        {
            "id": "nlvfl2",
            "title": "Best Song",
            "pollQuestion": {
                "id": "nbprqp",
                "title": "best-song",
                "displayText": "Best Song",
                "answer": [
                    {
                        "id": "qylaw4",
                        "title": "Bruno Mars – Locked Out Of Heaven",
                        "relatedItems": [
                            {
                                  "Name": "Bruno Mars",
                                  "id": "sljkur",
                                  "Bio": "Bio info here"
                            },
                            {} //Sometimes there's an empty object
                        ],
                        "winner": "true"
                    },
                    {
                        "id": "q05sb3",
                        "title": "Daft Punk – Get Lucky (ft. Pharrell Williams)",
                        "displayText": "Daft Punk – Get Lucky (ft. Pharrell Williams)",
                        "relatedItems": [
                            {
                                "Name": "Daft Punk",
                                "id": "d9sd84",
                                "Bio": "Bio info here"
                            }
                        ]
                    },
                    ...
                ]
            }
        },
        ...
    ]
}

Which maps to the following entities:

  • Category (votecategory values)
  • Nomination (answer values)
  • Artist (relatiedItems values)

Ive managed to setup object and relationship mappings for votecategory (category) -> answer (nomination), however I'm having a problem mapping nomination to artist.

What I need to do is have a 1:1 core data relationship setup between nomination and artist, and 1:N relationship setup between artists and nomination (one artist can have multiple nominations).

The problem is that "relatedItems" is an array, but in reality only contains 1 usable value, the related artist. This "should" be a 1:1 relationship from a data perspective, however the JSON maps it as a 1:N relationship, this confuses restkit (rightfully so).

How can I store the single item in the JSON relatedItems response as a single 1:1 relationship?

Thanks

Oli

1

1 Answers

0
votes

You could look at using a custom value transformer on that mapping which converts the array into a single object. Check out this question for some additional details.