Skip to content

Refactoring for SOC #26

@ghola

Description

@ghola

Normalizing/denormalizing (converting from object to/from array) and encoding/decoding (converting from array to/from string) are separate concerns. With the introduction of support for binary data the code inflated by quite a bit and has become had to manage. As such, I opted to follow the pattern used in the Symfony Serializer when I refactored the serializer to be used in my library. Here are the three main files that resulted:

  1. ObjectNormalizer deals only with transforming an object to and from an array.
  2. JsonEncoder deals with the actual json encoding/decoding, binary data encoding/decoding, and zero fraction support.
  3. JsonSerializer just uses the previous two.

In my code I stripped out the bit of functionality that deals with scalars because I'm only dealing with objects, but you get the point.

It wouldn't be a great effort to apply the same to zumba/json-serializer, but it would break BC compatibility so it would need to bump to version 3.x. You could also consider transforming this library to leverage the Symfony Serializer and just implement an encoder and a normalizer for it. This could potentially open a larger user base for it, as IMO the current normalizers used by the Symfony Serializer are useless.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions