Skip to content

JSON-API representer does not work with Roar::Client #15

@myabc

Description

@myabc

From @ekosz on January 6, 2015 15:42

Given the code

module SongsRepresenter
  include Roar::JSON::JSONAPI
  type :songs

  property :id
  property :name
end

class Song < OpenStruct
  include Roar::JSON::JSONAPI
  include SongRepresenter
  include Roar::Client
end

When I run

Song.new.get(uri: 'http://example.com/songs/1', as: 'application/json')

I get the error

NoMethodError: undefined method `deserialize' for #<Song>
    from /roar-1.0.0/lib/roar/http_verbs.rb:65:in `handle_response'
    from /roar-1.0.0/lib/roar/http_verbs.rb:40:in `get'

I then tried replacing Roar::JSON::JSONAPI with Roar::JSON in the client (as it does have #deserialize there) but I then got this error instead:

TypeError: no implicit conversion of String into Integer
    from /roar-1.0.0/lib/roar/json/json_api.rb:45:in `[]'
    from /roar-1.0.0/lib/roar/json/json_api.rb:45:in `from_hash'
    from /roar-1.0.0/lib/roar/json/json_api.rb:126:in `from_hash'
    from /representable-2.1.3/lib/representable/json.rb:30:in `from_json'
    from /roar-1.0.0/lib/roar/json.rb:21:in `from_json'
    from /roar-1.0.0/lib/roar/json.rb:30:in `deserialize'
    from /roar-1.0.0/lib/roar/http_verbs.rb:65:in `handle_response'
    from /roar-1.0.0/lib/roar/http_verbs.rb:40:in `get'

As an aside, I also noticed the current README is out of date in a few locations regarding JSON-API. For example the README refers to the JSON-API module as Roar::JSON::JsonApi but in the source its Roar::JSON::JSONAPI.

Copied from original issue: trailblazer/roar#119

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