Repository: jeregrine/jsonapi (elixir)

Issue:
Empty has-many relationship does not appear in relationships
According to [the spec](http://jsonapi.org/format/#document-resource-object-linkage), an empty to-many relationship should be represented as an empty array in `relationships`. So something like this:

```
%{
  id: 1,
  text: "Hello",
  body: "Hello world",
  author: %{id: 2, username: "jason"},
  best_comments: []
}
```

would have a `relationships` field something like this:

```
{
  relationships: %{
    author: %{
      data: %{id: "2", type: "user"},
      links: %{related: "/user/2", self: "/mytype/1/relationships/author"}
    },
    best_comments: %{
      data: [],
      links: %{
        self: "/mytype/1/relationships/best_comments"
      }
    }
  }
}
```

Currently, the serializer omits an empty to-many relationship, so it looks like this:


```
{
  relationships: %{
    author: %{
      data: %{id: "2", type: "user"},
      links: %{related: "/user/2", self: "/mytype/1/relationships/author"
    }
  }
}
```

The [test for handling an empty relationship](https://github.com/jeregrine/jsonapi/blob/master/test/serializer_test.exs#L184), specifies this behavior, but it seems to be at odds with the spec.

Would you accept a PR to serialize empty to-many relationships as empty lists? The change would definitely change responses for users of the library, but in a good way I think, bringing responses more in line with the spec.

Pull request description:
Serialize empty relationship
Fixes #112 by serializing relationship arrays that are empty.

Patch:
diff --git a/lib/jsonapi/serializer.ex b/lib/jsonapi/serializer.ex
index 338e827..04574df 100644
--- a/lib/jsonapi/serializer.ex
+++ b/lib/jsonapi/serializer.ex
@@ -125,7 +125,7 @@ defmodule JSONAPI.Serializer do
   defp generate_view_tuple(view) when is_atom(view), do: {view, :include}
 
   def is_data_loaded?(rel_data) do
-    assoc_loaded?(rel_data) && (is_map(rel_data) || (is_list(rel_data) && !Enum.empty?(rel_data)))
+    assoc_loaded?(rel_data) && (is_map(rel_data) || is_list(rel_data))
   end
 
   def encode_relation({rel_view, rel_data, _rel_url, _conn} = info) do


Test patch:
diff --git a/test/serializer_test.exs b/test/serializer_test.exs
index 449a7da..195b2f1 100644
--- a/test/serializer_test.exs
+++ b/test/serializer_test.exs
@@ -181,7 +181,8 @@ defmodule JSONAPISerializerTest do
     assert attributes[:body] == data[:body]
 
     assert encoded_data[:links][:self] == PostView.url_for(data, nil)
-    assert map_size(encoded_data[:relationships]) == 1
+    assert map_size(encoded_data[:relationships]) == 2
+    assert encoded_data[:relationships][:best_comments][:data] == []
 
     assert Enum.count(encoded[:included]) == 1
   end