4

I am trying to use ActiveModel::Serializer in conjunction with a PostgreSQL database.

The problem I am having is that whenever I include a json type column in a serializer I get:

SystemStackError (stack level too deep):
  actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:70

I don't want to do this as I need access to the data before returning it.

From schema.rb:

create_table "jobs", force: true do |t|
    t.integer  "user_id"
    t.string   "tool"
    t.string   "name"
    t.json     "options"
    t.integer  "status"
    t.string   "version"
    t.datetime "created_at"
    t.datetime "updated_at"
end

job_serializer.rb:

class JobSerializer < ApplicationSerializer
    attributes :id, :tool, :name, :status, :options, :version, :created_at

    has_many :inputs, serializer: FileLinkSerializer
end

Works fine if I remove :options from the attributes but crashes when it is included as above.

1
  • I was just wondering how serializers might behave with a json column, made a quick serch and there we go :) Thanks. Commented Jul 16, 2019 at 17:44

1 Answer 1

2

The problem is with having a field named options. I wrapped that field in a field called called tool_options and everything worked fine.

class JobSerializer < ApplicationSerializer
  attributes :id, :tool, :name, :status, :tool_options, :version, :created_at
end

class Job < ActiveRecord::Base
  def tool_options
    options
  end
end

(In reality I'll be changing my schema as its not too late.)

Sign up to request clarification or add additional context in comments.

1 Comment

Just came across the same issue in active_model_serializers 0.8. It doesn't happen in 0.9 as the clashing options feature seems to have been removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.