Skip to content

Serializer not emitting JSON API spec #1847

Open
@kjs3

Description

@kjs3

Expected:

In Rails, when configured with ActiveModelSerializers.config.adapter = :json_api

I expected using ArticleSimpleSerializer.new(article).as_json (or .to_json) outside of a controller to emit JSON in JSON API format including data, type, and attributes root keys.

Actual:

I get JSON object with Serializer attributes. Essentially what I would have expected in
json["data"]["attributes"]

Steps to reproduce

I have a serializer for an Article model but named ArticleSimpleSerializer so automatic lookup with…

ActiveModelSerializers::SerializableResource.new(article)

… doesn't work.

Rendering in a controller does emit JSON API format.

render status: :ok, json: @article, serializer: ArticleSimpleSerializer

I can't seem to get this same output outside of a controller.

Environment

ActiveModelSerializers Version 0.10.2:

ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin15]:

Mac OS 10.11.5

Rails 4.2

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