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

: try to improve this double parsing #307

Open
github-actions bot opened this issue Sep 28, 2022 · 0 comments
Open

: try to improve this double parsing #307

github-actions bot opened this issue Sep 28, 2022 · 0 comments
Assignees
Labels

Comments

@github-actions
Copy link

# TODO:: try to improve this double parsing

require "../utilities/*"

module PlaceOS::Api
  abstract class Application < ActionController::Base
    macro inherited
      Log = ::PlaceOS::Api::Log.for(self)
    end

    # Customise the request body parser
    add_parser("application/json") do |klass, body_io|
      json = body_io.gets_to_end
      object = klass.from_json(json)

      # TODO:: try to improve this double parsing
      if object.is_a?(::PlaceOS::Model::ModelBase)
        object = object.class.new
        # we clear the changes information so we can track what was assigned from the JSON
        object.clear_changes_information
        object.assign_attributes_from_json(json)
      end

      object
    end

    # Helpers for controller responses
    include Utils::Responders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant