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

Deserializer #210

Closed
denniscastro opened this issue Jul 22, 2019 · 12 comments · Fixed by #222
Closed

Deserializer #210

denniscastro opened this issue Jul 22, 2019 · 12 comments · Fixed by #222

Comments

@denniscastro
Copy link

Hi,

The Serializer works fine. but I would like to know if there is any plan to implement Deserializer module?, If not, What do you recommend to use for it?

@jeregrine
Copy link

You mean take a jsonapi document and hydrate some a model graph?

@hernanvicente
Copy link

hernanvicente commented Aug 25, 2019

@jeregrine probably @denniscastro did mean something like this:

# Gemfile
gem 'jsonapi-rails'

# app/controllers/posts_controller.rb
class PostsController < ApplicationController
  deserializable_resource :post, only: [:create, :update]

  def create_params
    params.require(:post).permit(:title, :content, :tag_ids)
  end

  def create
    post = Post.create(create_params)
    render jsonapi: post,
           include: [:author, comments: [:author]],
           fields: { users: [:name, :email] },
           status: :created
  end
end

I would be interested, too, to know if there is a recommended way to accomplish something similar with this package?

@denniscastro
Copy link
Author

Hi

Yes, the deserializer parses the jsonapi params to hash attributes for the model can build his intance.

@jgelens
Copy link
Contributor

jgelens commented Oct 7, 2019

https://github.com/vt-elixir/ja_serializer/blob/master/lib/ja_serializer/params.ex has a nice way to deserialize all the attributes and relations.

@jherdman
Copy link
Contributor

jherdman commented Oct 7, 2019

OK, that seems pretty interesting. Would you be interested in putting together an issue that proposes a solution?

@snewcomer
Copy link
Contributor

This was one thing I missed in past projects when I moved from ja_serializer to jsonapi. I've generally used it as a plug to flatten the incoming params for changeset casting.

def parse_data(%{"data" => data}), do: JaSerializer.Params.to_attributes(data)

So I like this idea!

@jgelens
Copy link
Contributor

jgelens commented Oct 8, 2019

The code can be used as-is. Just add the copyright according to JASerializer license and rename the module to match JSONAPI?

@doomspork
Copy link
Member

@jgelens interested in tackling this for Hacktoberfest?

@psteininger
Copy link

I have user https://github.com/vt-elixir/ja_resource/ in the past, and found it quite useful. It seems like development on this kind of stopped a year ago or even more. It was a really clever way to build a complete JSONAPI stack. The only thing missing for me was handling submitting objects with child entities all at once, be it through side-posting or breaking the spec and including data in relationships.

@doomspork
Copy link
Member

@psteininger we're open to PRs if someone wanted to take a crack at implementing the deserializer functionality for this package 👍

@snewcomer
Copy link
Contributor

@psteininger @denniscastro We do have an UnderscoreParameters plug you can add to your controller pipeline! Does that help you?

@snewcomer
Copy link
Contributor

snewcomer commented Feb 29, 2020

Upon further thought @denniscastro was this what you were getting at? Effectively taking a jsonapi document and making it easy for changeset casting...(I think this was said a few times :) )

#223 (comment)

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.

8 participants