Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested attributes don't serialize correctly #131

Closed
pdesjardins90 opened this issue Sep 21, 2016 · 3 comments · Fixed by #132
Closed

Nested attributes don't serialize correctly #131

pdesjardins90 opened this issue Sep 21, 2016 · 3 comments · Fixed by #132

Comments

@pdesjardins90
Copy link

pdesjardins90 commented Sep 21, 2016

I have this body on a post:

{
    "data": {
        "type": "saule",
        "attributes": {
            "coolness": "pretty cool up here",
            "can-read-top-level-dashed-attribute": true,
            "but": {
                "coolness": "not so much down here",
                "can-read-nested-dashed-attribute": false   
            }
        }
    }
}

I'm within my rights to do that, according to the json api constitution, but saule doesn't parse the nested dashed keys, it only works if they're camelCased (default web api behavior I guess)

@joukevandermaas
Copy link
Owner

Saule mimics Ember Data behavior here, which is arguably a better fit for JavaScript than C#. 'Complex' attributes are not touched. The reason it works with camel cased fields is that JSON.Net automaticallly handles those.

Is there a particular reason you don't want to serialize these fields as a relationship instead? I don't have any particular objections to adding support for this in Saule, but I'm not sure it is needed.

@pdesjardins90
Copy link
Author

The only reason would be for 'value objects', i.e. things that are not considered as whole resources (deserving of an id and specific routes).

Of course in this case I could just put everything on the top level and parse it in the appropriate hierarchy in my controllers, but what if I have an array of nested stuff with dashed names? And also, that may not be as important to everybody, but I feel that flattening the attributes hierarchy would lessen the clarity of the body in some cases (let's say I have over 25 attributes to post at once, and for better comprehension there should be 'sections' in those attributes, you see my point?)

@joukevandermaas
Copy link
Owner

I published a new pre-release with a fix for this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants