(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)...