{"action":"closed","issue":{"url":"https://api.github.com/repos/katharsis-project/katharsis-core/issues/159","labels_url":"https://api.github.com/repos/katharsis-project/katharsis-core/issues/159/labels{/name}","comments_url":"https://api.github.com/repos/katharsis-project/katharsis-core/issues/159/comments","events_url":"https://api.github.com/repos/katharsis-project/katharsis-core/issues/159/events","html_url":"https://github.com/katharsis-project/katharsis-core/issues/159","id":116938888,"number":159,"title":"Field Resource POST  throws 500 for To-Many relationships","user":{"login":"amareen1988","id":12468439,"avatar_url":"https://avatars.githubusercontent.com/u/12468439?v=3","gravatar_id":"","url":"https://api.github.com/users/amareen1988","html_url":"https://github.com/amareen1988","followers_url":"https://api.github.com/users/amareen1988/followers","following_url":"https://api.github.com/users/amareen1988/following{/other_user}","gists_url":"https://api.github.com/users/amareen1988/gists{/gist_id}","starred_url":"https://api.github.com/users/amareen1988/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amareen1988/subscriptions","organizations_url":"https://api.github.com/users/amareen1988/orgs","repos_url":"https://api.github.com/users/amareen1988/repos","events_url":"https://api.github.com/users/amareen1988/events{/privacy}","received_events_url":"https://api.github.com/users/amareen1988/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-14T17:20:09Z","updated_at":"2015-11-15T14:40:26Z","closed_at":"2015-11-15T14:40:25Z","body":"__Symptoms__:\r\nAssume we have a `Parent.class` resource which has _To-Many_ relationship with a `Child.class` resource using a list reference (i.e., `List<Child> children`). If an attempt is made to POST a new child using a Filed Resource Post through the parent (i.e., __POST /parent/{parent_id}/children__), then the `handle` method of `FieldResourcePost.class` throws a NullPointerException which results in a server error 500. \r\n\r\n__Main Cause__:\r\nInside the `handle` method of `FieldResourcePost.class` the `relationshiptResourceType` is being looked up using the following statement: \r\n`String relationshipResourceType = resourceRegistry.getResourceType(baseRelationshipFieldClass);` \r\nHowever, `baseRelationshipFieldClass` in this case is equal to `java.util.List` and the method above will end up returning `null` because a `java.util.List` is not a valid `@JsonApiResource`. The `getResourceType` method loops on annotations which are `instanceof` `JsonApiResource`.\r\n\r\n__Resolution__:\r\nChange the line:\r\n`String relationshipResourceType = resourceRegistry.getResourceType(baseRelationshipFieldClass);` \r\nin the `handle` method of class `FieldResourcePost.class` to the following:\r\n`String relationshipResourceType = resourceRegistry.getResourceType(relationshipFieldClass);` \r\n"}}