Skip to content

Response model will send null data when data is object that does not extend JsonSerializable #15

Description

@ReservedDeveloper

Due to the introduction of the json serializer handler in 7fcf74c, the response model no longer sends along data that is of type ArrayCollection (or other objects that do not natively convert to json).

The reason for this is that ArrayCollection does not implement \JsonSerializable, which can be used by json_encode to process objects.

So in \DLinsmeyer\Bundle\ApiBundle\Response\Model\Response::toArray() when it calls $this->getData(), it's getting an array collection
and when \DLinsmeyer\Bundle\ApiBundle\Serializer\Adapter\JsonEncodeAdapter::serialize() goes to process that it can't decipher and tosses it out.

The fix here could be one of the following:

  • Introduce a check to see if the given data point is serializable (i.e. is_array, is_scalar, etc). If not, convert to known serializable value
    • The issue here is that you would need to add multiple checks. May require a callback that could be defined on a per-project basis
  • Add a note in the documentation that properties on the response model must be directly serializable

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions