ruby-on-railsfastjsonapi

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


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


Solution

  • 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