angular2-jsonapi icon indicating copy to clipboard operation
angular2-jsonapi copied to clipboard

Refactoring: Serializers

Open reva2 opened this issue 9 years ago • 0 comments

Hi guys,

Currently, code that parse responses and generate payloads for requests spread out between two components JsonApiDatastore and JsonApiModel. This cause unnecessary complexity of each component and high coupling between them. Code is a bit messy and it hard to test it. Also it's not flexible because end user couldn't change any parts of data handling process.

I think that we should refactor this code to series of separate components - serializers. We should have three types of serializers:

  • ResponseSerializer - it should be able to convert response data to DocumentModel (see #26). Under hood it should use models serializers (see below) to convert separate resources.
  • RequestSerializer - it should be able to convert specified JsonApiModel to request payload. Again, under hood it should use models serializers to convert separate resource.
  • ModelSerializer - it should support two things: unserialize part of response data to JsonApiModel instance and serialize JsonApiModel instance into part of request payload.

All serializers should be configurable. I.e. we need to support following scenarios:

  • user should be able to replace default response, request and model serializers
  • user should be able to use cumstom serializer for specific JsonApiModel

Please let me know what you think about it.

reva2 avatar Oct 12 '16 12:10 reva2