Giter Club home page Giter Club logo

Comments (6)

yosiat avatar yosiat commented on August 22, 2024 1

@bbay Hi!

The API I wrote above is planned for future versions of Panko, currently, it won't work - since Panko::Serializer constructor doesn't accept a model (in your case user).

I updated the docs, sorry for the inconvenience - e139348.

from panko_serializer.

yosiat avatar yosiat commented on August 22, 2024

Hi @dkulchenko ,

Sorry for late response, the proper solution is to break Panko's API, so instead of what you wrote you could write:

render json: Panko::Response.new(
      status: 'active',
      user: UserSerializer.new(user)
)

This is something I am planning for a later version (probably 1.*), but not for now.

The current solution will be to use new Panko API (which I will add public documentation soon) is that response creator API.

render(
  json: Panko::Response.create do |r|
    {
      status: 'active',
      user: r.serializer(user, UserSerializer)
    }
  end
)

from panko_serializer.

bbay avatar bbay commented on August 22, 2024

hello @yosiat

What's the current preferred solution for this?

render(
  json: Panko::Response.create do |r|
    {
      status: 'active',
      user: r.serializer(user, UserSerializer)
    }
  end
)

This worked for me, but I don't see it anywhere in the docs, the first version you provided didn't work for me.

thanks!

from panko_serializer.

bbay avatar bbay commented on August 22, 2024

thanks!

from panko_serializer.

yosiat avatar yosiat commented on August 22, 2024

@bbay closing this issue, feel free to re-open it if you want to ask more questions on this topic.

from panko_serializer.

bbay avatar bbay commented on August 22, 2024

hello again @yosiat
Following up from my last post where I needed serialization of a single object.
I need now to pass some options and I noticed it is not possible due to the implementation in ResponseCreator (response.rb)

wdyt about adding this change?

   # in lib/panko/response.rb
    def self.serializer(data, serializer, options = {})
      json serializer.new(options).serialize_to_json(data)
    end

So I can then do something like this:

render(
  json: Panko::Response.create do |r|
    {
      status: 'active',
      user: r.serializer(user, UserSerializer, context: {index: true})
    }
  end
)

from panko_serializer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.