Skip to content

: try to improve this double parsing #307

@github-actions

Description

@github-actions

# 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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions