Skip to content

JSON adapter with empty array does not maintain root key #1153

Closed
@meltingice

Description

@meltingice

If you attempt to serialize an empty array with the JSON adapter and ArraySerializer, the root key becomes an empty string. This issue is present in 0.10.0.rc2 and the latest master branch commit at this time (17c353826056bc3eac3e6d6a2fd081af175bb6ad).

Example Code

class Api::V1::ArticlesController < Api::V1::BaseController
  def index
    @articles = []
    render json: @articles, each_serializer: Api::V1::ArticleSerializer
  end
end

Expected

{
  "articles": []
}

Actual

{
  "": []
}

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