fast_jsonapi icon indicating copy to clipboard operation
fast_jsonapi copied to clipboard

syntax sugar `render` like other serializers

Open yoshi12u opened this issue 6 years ago • 2 comments

Hi team! I suppose almost everyone use new and serialized_json at the same time, so I suggest that FastJsonapi::ObjectSerializer should have render, which is syntax sugar of .new(args).serialized_json. A situation when tihs feature would be useful is, for example, when you want to serialize a poro with other serializer(e.g. serialize pagy with blueprinter to generate a json of pagination links). If FastJsonapi has render, we can use any serializer with polymorphism because serializers recommended in the README.md of active_model_serializers, such as blueprinter and jsonapi-rb , have render to serialize objects.

yoshi12u avatar Apr 12 '19 19:04 yoshi12u

this would be great!

zion avatar Apr 16 '19 22:04 zion

To some extend, this is related to the #175 and #102 and I would argue how generic a render method can be in the context of a generic serialization library.

Just some of reasons why this might be very much framework implementation specific:

  • content type handling
  • pagination (as already mentioned)
  • resource vs. error serialization
  • single vs. collection serialization
  • serializer params/args DRY handling

As I mentioned before, it's up to the fast_jsonapi team to decide how generic the library should be. In the meantime consider taking a look at stas/jsonapi.rb gem which does this for you.

stas avatar Jul 01 '19 18:07 stas