Skip to content

#as_json option :only Not working #1851

Open
@brosintoski

Description

@brosintoski

Expected behavior vs actual behavior

Expected: Only fields passed to only option are returned from as_json.

Actual: All fields/attributes of the serializer are returned.

Steps to reproduce

  1. Create an activerecord model called User with attributes: name and status.
  2. Create a serializer for that model with attributes :id, :name, :status
  3. From console execute following steps:
    UserSerializer.new(User.new(name: 'foo bar', status: 'active')).as_json(only: [:id, :name])
  4. Note that status is also returned.

Environment

ActiveModelSerializers Version (commit ref if not on tag): aa4d89a

Output of ruby -e "puts RUBY_DESCRIPTION": ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]

OS Type & Version: OS X v10.11.5

Integrated application and version (e.g., Rails, Grape, etc): rails 4.2.6

Backtrace

(e.g., provide any applicable backtraces from your application)

Additonal helpful information

(e.g., Gemfile.lock, configurations, PR containing a failing test, git bisect results)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions