{"action":"created","issue":{"url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/35","labels_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/35/comments","events_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/35/events","html_url":"https://github.com/fotinakis/jsonapi-serializers/issues/35","id":120865957,"number":35,"title":"Included assuming default class name to build Serializers","user":{"login":"hlegius","id":36469,"avatar_url":"https://avatars.githubusercontent.com/u/36469?v=3","gravatar_id":"","url":"https://api.github.com/users/hlegius","html_url":"https://github.com/hlegius","followers_url":"https://api.github.com/users/hlegius/followers","following_url":"https://api.github.com/users/hlegius/following{/other_user}","gists_url":"https://api.github.com/users/hlegius/gists{/gist_id}","starred_url":"https://api.github.com/users/hlegius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hlegius/subscriptions","organizations_url":"https://api.github.com/users/hlegius/orgs","repos_url":"https://api.github.com/users/hlegius/repos","events_url":"https://api.github.com/users/hlegius/events{/privacy}","received_events_url":"https://api.github.com/users/hlegius/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-07T20:57:08Z","updated_at":"2015-12-08T21:20:58Z","closed_at":"2015-12-07T21:54:44Z","body":"Hello there!\r\n\r\nI am trying to build a `included` JSON API schema within my Serializer, but I am got an error while try to find the serializer class.\r\n\r\nI've got:\r\n\r\n```\r\n  uninitialized constant Some::Other::Namespace::RequesterSerializer\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:263:in `const_get'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:263:in `block in constantize'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `each'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `inject'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `constantize'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/activesupport-4.2.4/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/jsonapi-serializers-0.3.0/lib/jsonapi-serializers/serializer.rb:210:in `find_serializer_class'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/jsonapi-serializers-0.3.0/lib/jsonapi-serializers/serializer.rb:214:in `find_serializer'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/jsonapi-serializers-0.3.0/lib/jsonapi-serializers/serializer.rb:351:in `block in find_recursive_relationships'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/jsonapi-serializers-0.3.0/lib/jsonapi-serializers/serializer.rb:347:in `each'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/jsonapi-serializers-0.3.0/lib/jsonapi-serializers/serializer.rb:347:in `find_recursive_relationships'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/jsonapi-serializers-0.3.0/lib/jsonapi-serializers/serializer.rb:290:in `block in serialize'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/jsonapi-serializers-0.3.0/lib/jsonapi-serializers/serializer.rb:287:in `each'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/jsonapi-serializers-0.3.0/lib/jsonapi-serializers/serializer.rb:287:in `serialize'\r\n     # /Users/hlegius/.rvm/gems/ruby-2.2.1@awesome-project/gems/jsonapi-serializers-0.3.0/lib/jsonapi-serializers/serializer.rb:20:in `serialize'\r\n```\r\n\r\nMy implementation:\r\n\r\n```ruby\r\n# Requester Serializer\r\nmodule My\r\n  module Awesome\r\n    module Responders\r\n      class Requester\r\n        include JSONAPI::Serializer\r\n\r\n        has_one :mailing_address\r\n        has_one :shipping_address\r\n\r\n        attribute :foo\r\n        attribute :bar\r\n      end\r\n    end\r\n  end\r\nend\r\n\r\n# Address Serializer \r\nmodule My\r\n  module Awesome\r\n    module Responders\r\n      class Address\r\n        include JSONAPI::Serializer\r\n\r\n        attribute :zip_code\r\n      end\r\n    end\r\n  end\r\nend\r\n\r\n# Domain Entity\r\nmodule Some\r\n  module Other\r\n    module Namespace\r\n      class Requester\r\n        # ...\r\n\r\n        def mailing_address\r\n          # ...\r\n        end\r\n\r\n        def shipping_address\r\n          # ...\r\n        end\r\n      end\r\n    end\r\n  end\r\nend\r\n\r\n# Returns Some::Other::Namespace::Requester object\r\nrequester = Some::Other::Namespace::RequesterRepository.find(...) \r\n\r\nMy::Awesome::Responders::Requester.serialize(requester) # runs pretty well, thanks!\r\nMy::Awesome::Responders::Requester.serialize(\r\n  requester,\r\n  include: ['mailing_address', 'shipping_address']\r\n) # fail with the error above.\r\n```\r\n\r\nSo, as far as I've debugged, it's when ActiveSupport `.constantize` that tries to build a `Some::Other::Namespace::RequesterSerializer` with some fixed convention created within `serialize.rb` file.\r\n\r\nDocumentation says that it's possible to customize this behavior, but I didn't figure out who to do this.\r\n\r\nIf you need further informations, I am totally willing to help to understand/solve this o/\r\n\r\nThanks for reading!"},"comment":{"url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/comments/163021282","html_url":"https://github.com/fotinakis/jsonapi-serializers/issues/35#issuecomment-163021282","issue_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/35","id":163021282,"user":{"login":"fotinakis","id":75300,"avatar_url":"https://avatars.githubusercontent.com/u/75300?v=3","gravatar_id":"","url":"https://api.github.com/users/fotinakis","html_url":"https://github.com/fotinakis","followers_url":"https://api.github.com/users/fotinakis/followers","following_url":"https://api.github.com/users/fotinakis/following{/other_user}","gists_url":"https://api.github.com/users/fotinakis/gists{/gist_id}","starred_url":"https://api.github.com/users/fotinakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fotinakis/subscriptions","organizations_url":"https://api.github.com/users/fotinakis/orgs","repos_url":"https://api.github.com/users/fotinakis/repos","events_url":"https://api.github.com/users/fotinakis/events{/privacy}","received_events_url":"https://api.github.com/users/fotinakis/received_events","type":"User","site_admin":false},"created_at":"2015-12-08T21:20:57Z","updated_at":"2015-12-08T21:20:57Z","body":"After looking through the code I'm not sure if we support this very well. You may want to try passing through the `serializer` option:\r\n\r\n```ruby\r\nJSONAPI::Serializer.serialize(requester, serializer: My::Awesome::Responders::Requester)\r\n```\r\n\r\nBut, I'm not sure if relationships will work well. There are some architecture changes we need to make to support this (somewhat discussed in https://github.com/fotinakis/jsonapi-serializers/issues/18) -- sorry we don't have a better answer for this namespace handling right now."}}