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

Splitting json adapter into two #958

Merged
merged 14 commits into from
Jun 16, 2015

Conversation

joaomdmoura
Copy link
Member

We discussed about the root option and how it shouldn't be a config but a different adapter itself.

This PR create a FlattenJson adapter that doesn't support root, the Json adapter in the other hand will now have root by default and you will still be able to manually set it with the root option.

FlattenJson is now the default adapter, the result still will be the same we had before, when the default was Json adapter without root.

@spastorino
Copy link
Contributor

Last tiny bit ...

curl http://localhost:3000/todos
{"todo":[{"id":1,"title":"Todo 1","completed":false,"order":1},{"id":3,"title":"Todo 8","completed":true,"order":2}]}

We would need that one the be todos as it was in old AMS, that's the way it plays nice with Ember's Rest adapter.

@joaomdmoura
Copy link
Member Author

@spastorino done.

  • Removed root option (removed the tests related to it)
  • Pluralizing root when using ArraySerializer

btw, as I mentioned there is no need to store the result for now.

@spastorino
Copy link
Contributor

curl http://localhost:3000/todos
{"todo":[{"id":1,"title":"Todo 1","isCompleted":null}]}

@joaomdmoura
Copy link
Member Author

@spastorino 😢 tested over here:
(you can check the code here)

Can you share ur controller code?
Did you defined ActiveModel::Serializer.config.adapter = :json?
Is it pointed to the last commit?

curl http://localhost:3000

{ 
  "posts": [
    {"id":1,"title":"Awesome Post","body":"Indeed a great one!","user":{"id":2,"name":"Mattew Crazy","age":33,"email":"mattew@crazy.com"}},
    {"id":2,"title":"Incredible Post","body":"Indeed another great one!","user":{"id":2,"name":"Mattew Crazy","age":33,"email":"mattew@crazy.com"}}
  ]
}

@joaomdmoura joaomdmoura force-pushed the spliting-json-adapter branch 3 times, most recently from ad3aa1b to eb5f189 Compare June 16, 2015 14:27
joaomdmoura added a commit that referenced this pull request Jun 16, 2015
@joaomdmoura joaomdmoura merged commit bc8fd0a into rails-api:master Jun 16, 2015
@@ -6,7 +6,7 @@ module Serialization

include ActionController::Renderers

ADAPTER_OPTION_KEYS = [:include, :fields, :root, :adapter]
ADAPTER_OPTION_KEYS = [:include, :fields, :adapter]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty big change. Prior to this, the root option always went to the adapter. Now it will always go to the serializer. Which code path should be dead? root to serializer or root to adapter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah @bf4 this is indeed a big change.
The idea is that root shouldn't be an option, but another adapter by itself.
This make it even easier to integrate with some js frameworks.
We also removed the option to set a specific root key, so the root isn't "going" to the serializer, but is the serializer the one that knows what it should be and the adapter the one the uses it or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to read through the code some more to make sure I understand the changes as they affect tests that were deleted or whose expectations were changed. It didn't break #954 (once I rebased it), but I think this is the kind of thing we should include in the README between 'how it works' and 'intended usage'...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we realized we forgot about the README, but I'm already updating it.
I'm glad it didn't broke #954 😄

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

Successfully merging this pull request may close these issues.

None yet

3 participants