Skip to content

Collection of POROs renders only first element #34

Closed
@wizardone

Description

@wizardone

Am I doing something wrong? I cannot seem to properly render a collection of objects. Looked across the documentation but could not find anything.. It looks really basic and this is what gets me confused..

results = [AddressFinder::AddressSearch::Result.new(a: "Some address", pxid: "qwe1", v: 1), AddressFinder::AddressSearch::Result.new(a: "Some other address", pxid: "qwe2", v: 1)]
render json: JSONAPI::Serializable::Renderer.new.render(
  results,
  class: { 'AddressFinder::AddressSearch::Result': AddressFinderSerializer }
)
class AddressFinderSerializer < JSONAPI::Serializable::Resource
  type 'AddressFinder'

  attribute :address do
    @object.a
  end
end

End Result:

{
  'data' => [
    {
      'id' => '',
      'type'=> 'AddressFinder',
      'attributes' => {
        'address' => 'Some address'
      }
    }
  ]
}

Expected result:

{
  'data' => [
    {
      'id' => '',
      'type'=> 'AddressFinder',
      'attributes' => {
        'address' => 'Some address'
      }
    },
    {
       'id' => '',
       'type'=> 'AddressFinder',
       'attributes' => {
         'address' => 'Some other address'
       }
     }
   ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions