#75 new
r2d2

Trouble deserializing (nested) collections in JSON

Reported by r2d2 | February 25th, 2010 @ 10:45 AM

(I guess this is more of a feature request than an actual bug)

When generating a JSON output with a line like this

format.json{render :text => items .to_json(:include => [:friends]), :status => :ok}

and the "friends" attribute is a collection of objects (e.g. of "friend" objects), the JSON output looks something like

[

"person": {
  "name": "A",
  "friends": [
    {
      "name": "B"
    }
  ]
}

]

The "friend" objects in the "friends" collection are serialized directly into the JSON array, they are not wrapped like {"friend": {...}} as are the "person" objects on the top level (i.e. the elements of the top-level array). This cannot be handled by the code in "NSObject+JSONSerializable", which depends on the wrapped style. An exception is produced as a result.

A solution would be to take the property name (e.g. "friends") and derive from it the class the contained elements must be of (e.g. "friend"). Of course, this doesn't work in all cases (e.g. when there are "person" objects in the "friends" list)...

No comments found

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Port of Rails' ActiveResource framework to the iPhone.

Shared Ticket Bins

People watching this ticket

Pages