Skip to content

Serializing an entity immediately after creating it results in an error #90

Open

Description

@daniel-memo-ict

Steps

  1. Create an entity (Any entity, doesn't matter which one, Address, Barcode, Contact,etc)
  2. pass it through json_encode.

Expected behavior:
Returns a json encoded string of all the properties available in the entity

Actual behavior:
Throws an exception

What exactly is currentService being used for? Currently I can only see it being set, and not being read anywhere except to throw the mentioned exception. getCurrentService() does not seems to be used.
And why must it be set if it's not used anywhere?
If it is absolutely necessary to have, can the check be moved elsewhere so it doesn't interfere with the simple process of serializing the entity's properties?

Activity

  1. firstred commented on Jan 17, 2024

    @firstred
    Owner

    I believe it used to provide some serialization context for the SOAP API, equivalent to the context of a Symfony Serializer. It somehow ended up in the entity itself rather than on the serializer. Now that support for the SOAP API has been dropped it is no longer necessary, I think.

    Do you think it can be removed in its entirety? It would be nice to get rid of legacy code like this.

  2. daniel-memo-ict commented on Jan 22, 2024

    @daniel-memo-ict
    Author

    In theory, as I don't see it being used anywhere, it should be possible to remove it entirely without affected anything else in the package. I of course don't know if there are any implementations that may use the currentService property.

  3. SanderFlooris commented on Apr 3, 2025

    @SanderFlooris

    We use this package to get the nearest PostNL pickup points and we recently ran into this issue while migrating to V2.

    Not sure what the exact cause/solution is, but this seemed to fix it for us.

            foreach ($locationResults->getResponseLocation() as $responseLocation) {
                $responseLocation->getAddress()->setCurrentService(LocationServiceInterface::class);
                $responseLocation->getOpeningHours()->setCurrentService(LocationServiceInterface::class);
                $responseLocation->getSustainability()->setCurrentService(LocationServiceInterface::class);
            }

    After this it was able to JSON serialize it properly without throwing a ServiceNotSetException.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions