Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SerializationGraphNavigator unaware of serializeNull change of context when altered in PreSerializeEvent #1157

Closed
gabrielspiteri-highlight opened this issue Jan 24, 2020 · 5 comments

Comments

@gabrielspiteri-highlight
Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? no

SerializationGraphNavigator doesn't take into account a possible change in the serializeNull property of the context when altered in a PreSerializeEvent.

Steps required to reproduce the problem

  1. Configure JMS to serialize_null: false
  2. Start serializing an object that has a null value property
  3. Add a pre serialize event subscriber
  4. In the event call $event->getContext()->setSerializeNull(true)

Expected Result

  • The object's properties with a null value should be included in the resulting JSON

Actual Result

  • The object's properties with a null value are not included.
@goetas
Copy link
Collaborator

goetas commented Jan 25, 2020

::setSerializeNull(true) should not be called inside event listeners... actually should trigger an exception if done so. So most likely it is a bug.

When the serialization is started, the context should be in read-only mode.
See

private function assertMutable(): void
, assertMutable should be called inside setSerializeNull

@goetas
Copy link
Collaborator

goetas commented Jan 25, 2020

See #1159

@goetas goetas closed this as completed Jan 25, 2020
@gabrielspiteri-highlight
Copy link
Author

Alright is there a better way to configure specific entities only to serialize nulls ?

@goetas
Copy link
Collaborator

goetas commented Jan 28, 2020

hmm, not really... serialize null is defined in the context, there is no easy way to do it per-entity

@gabrielspiteri-highlight
Copy link
Author

gabrielspiteri-highlight commented Jan 28, 2020

@goetas Well changing it in the PreSerializeEvent was pretty easy :) ... However I think we could handle it if the Navigators shouldSerializeNull property had a setter function ? ... Currently we worked around the limitation by calling the initialize function with an altered context object than in PostSerialize we set it back to its original value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants