Don't try to serialize nil with an entity serializer

If the entity (such as a reference to another object) is nil,
the `entity` method will still try to serialize nil using the
passed in block or serializer class, which will often raise a
`NoMethodError` on `nil`.

Here, we don't try to serialize unless the item actually exists
to serialize it, otherwise we return nil.