#<FastJsonapi::MandatoryField: id is a mandatory field in the jsonapi spec>

6.5k Views Asked by At

When trying to pass an enum object to serializer I get the following error:

#<FastJsonapi::MandatoryField: id is a mandatory field in the jsonapi spec>

@drop_down_values = Organisation.ownerships where @drop_down_values has the enum values from ownership column.

render json: DropDownValueSerializer.new(@drop_down_values).serialized_json

1

There are 1 best solutions below

0
On BEST ANSWER

I figured out that FastJsonAPI expects object id by default. Hence, when passing object to serializer it expects id to be present in the object passed.

'https://github.com/Netflix/fast_jsonapi/issues/100' this has been logged as an issue in FastJsonAPI.

The below works properly: render json: DropDownValueSerializer.new(Organisation.first).serialized_json