postnl-api-php icon indicating copy to clipboard operation
postnl-api-php copied to clipboard

Serializing an entity immediately after creating it results in an error

Open daniel-memo-ict opened this issue 2 years ago • 3 comments

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?

daniel-memo-ict avatar Jan 16 '24 15:01 daniel-memo-ict

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.

firstred avatar Jan 17 '24 00:01 firstred

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.

daniel-memo-ict avatar Jan 22 '24 09:01 daniel-memo-ict