Active_model_serializers: Deserialize collections

Created on 29 Jan 2016  路  5Comments  路  Source: rails-api/active_model_serializers

Hello! I want to deserialize attached collection and I use ActiveModelSerializers::Deserialization.jsonapi_parse(*args) method for that. Problem is that after deserialization I receive empty hash like { }. Could you explain me how it should work or there is another possibility to solve this problem? Thanks!

{
  "data": [{
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!"
    },
    "links": {
      "self": "http://example.com/articles/1"
    },
    "relationships": {
      "author": {
        "links": {
          "self": "http://example.com/articles/1/relationships/author",
          "related": "http://example.com/articles/1/author"
        },
        "data": { "type": "people", "id": "9" }
      },
      "comments": {
        "links": {
          "self": "http://example.com/articles/1/relationships/comments",
          "related": "http://example.com/articles/1/comments"
        },
        "data": [
          { "type": "comments", "id": "5" },
          { "type": "comments", "id": "12" }
        ]
      }
    }
  }]
}
Question

All 5 comments

Current implementation is for single resource. Wanna help out?

Something along the line of

params.map { |x| ActiveModelSerializers::Deserialization.jsonapi_parse(x) }

@remear Just for clarification: Was this closed because this is a feature currently in development? If not, what is the best way to leave an issue open as a feature request?

@mrryanjohnston The original question seemed answered. If you're looking for something more in the way of a feature, just open a new issue, give a detailed description and maybe an example of what you're looking for. You may also want to reference this issue if applicable.

As it popped up in another issue, I'll say it here as well. The snipped I posted above is not exact, you have to do:

params[:data].map { |x| ActiveModelSerializers::Deserialization.jsonapi_parse(data: x) }
Was this page helpful?
0 / 5 - 0 ratings