Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#<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

like image 620
Nandhini Avatar asked Nov 24 '25 19:11

Nandhini


1 Answers

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

like image 197
Nandhini Avatar answered Nov 26 '25 09:11

Nandhini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!