-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Added XML support #448
Added XML support #448
Conversation
👍 |
I would love it merged. |
if serializer | ||
super(serializer, options) | ||
else | ||
super(resource, options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to change super to this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods created using define_method require explicit params in super
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh ya, we move to define_method 👍
There are no tests for this, we need tests. |
I have developed more on this already and written tests for it all. I will push it, hopefully this weekend. The one big (and only real) concern is still however that XML needs a root, and that elements in arrays need a wrapper tag as well, so eg: { posts: [
{ title: "XML",
body: "ActiveModel::Serializer should support XML" }
]},
{ comments: [
{ user_id: 1,
body: "Agreed!" },
{ user_id: 5,
body "I don't..."}
]} Would need to be something like this XML <result>
<posts>
<post>
<title>XML</title>
<body>ActiveModel::Serializer should support XML</body>
</post>
</posts>
<comments>
<comment>
<user_id>1</user_id>
<body>Agreed!</body>
</comment>
<comment>
<user_id>5</user_id>
<body>I don't...</body>
</comment>
</comments>
</result> |
I can help if you push. |
@ncr I have pushed what i have created so far. It's not done, and few of the specs still fails... but at least there is something to work from, and to discuss :). I will continue to work on this. |
@jokklan I am interested in this too. Can I help? |
I would love to help getting this integrated. |
I'm using your fork now. You might have saved me a lot of trouble - cheers! |
I'm sad to say that things like |
@alcesleo I haven't have time to complete this yet, but i will come back to it soon (hopefully this weekend). The whole implementation needs some refactorings and clean up. @rewritten Any help would be appreciated 👍 I can ping you when i have completed the last clean up, and then maybe you could look it through? |
@jokklan That sounds fantastic, I would totally buy you a beer (or three). |
@jokklan thanks for merging, let me know if there is anything else to refactor. |
@dyanisse I'll rebase with master and then let's see :) |
@jokklan please ping me! |
@alcesleo @rewritten or any one else that want to help: their need to be made a decision on XML roots. I think the class name would be a good default and how the XML parser works now, but their also have to be a option to set your own root for each serializer object, and/or in a global configuration (partly implemented). Adding tests and documentation for this would be really helpful, then can I (or anyone willing) implement it soon. If it's to unclear then please ask :)! Otherwise know that I plan getting back to this real soon. I know I keep postponing this PR I'm just a little busy, but I promise I'll finish this! |
@jokklan The underscored name of the serialized class could be a good default option, but also it should be configurable, yes. Do ou want us to provide (failing) tests for that? |
Im writing some refactorings and improvements now. I'll try to add some tests, but i'll have to figure out a clever way to test it without just copy all the json tests :) |
This should now work :). The old Their still needs to be made some tests, right now is their only integration tests. Also a good documentation section needs to be added. I will continue to work on this, but should anyone want to make some unit test or write some documentation, then please do 👍, would help a lot! Would also be nice to get some feedback from some of the moderators. Any thoughts @spastorino ? |
@jokklan Hi! Sorry I haven't been able to look it over as much as I wanted to, I am trying it out now but I still can't get the url-helpers working. Not quite sure what has changed that made them stop functioning. |
@alcesleo that sounds very strange, i can't figure out how this should affect url helpers. |
@jokklan Me neither, but it works in the original version. |
Some obscure inheritance or super-call that has changed maybe? |
Properly something to do with that this branch comes from master, so it's something that's introduced in master since last stable release. |
faceplam it actually says something about it in the first paragraph of |
This works great for me now! Thanks @jokklan! Let me know if you want to cash in on those beers. |
Is there more work needed to get this merged? Hoping to use AMS but unfortunately XML generation is a requirement for us. |
@GeekOnCoffee Hi, there is an ongoing discussion around the future of AMS. Adding XML is not a priority and, even though pluggable formatters are somewhere in the plan, an XML variant doesn't seem to be within what we'd like to implement first. Please check the discussion here. |
Yes. Please see here: https://groups.google.com/forum/#!topic/rails-api-core/8zu1xjIOTAM I have some concerns about putting this in 0.9, but I wouldn't mind for 0.10 (and the eventual 1.0) to have XML support, and it should be even easier, with the new architecture. Let me think about this some more before merging. |
Yes. I wouldn't mind this feature in |
Now that v0.10 is available, is it worth re-opening the discussion around XML support? Is it as simple as just adding a new adapter that derives from the JSON adapter and/or the JSON API adapter, and then just calls The challenge this would address is being able to render the "equivalent" JSON or XML output on demand. Over time clients can move away from the XML interface to the better JSON layout. |
@reidmorrison I would help you write an add-on that adds an XML adapter, but, at present, it's not a good fit for AMS. Additionally, active model xml serializers have been extracted from Rails 5, so it would be problematic to make that a dependency. Please open a new issue if you'd like to discuss more, esp with an example of what your use-case is. |
Hallo
I know that you have said before that you are not focusing on XML support at the time being, but I''ll need it for one of my own projects, so i have build it anyway. Even though it's not done, was it really simple to implement, as a hash easily can be transformed into XML. The only obstacle i came across was that XML needs a root, and json does not, but that doesn't seem to bad. Rabl eg can also render json without root with the same template as it will render xml.
I don't know if you are at all interested, but i can't see a reason not to?
Best regards
/Johan