-
-
Notifications
You must be signed in to change notification settings - Fork 587
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
Serialization Context Naming Strategy #1394
base: master
Are you sure you want to change the base?
Serialization Context Naming Strategy #1394
Conversation
I can't find the cause of error in scrutinizer. |
Hi! @dgafka - code looks good, thanks! Could you try to rebase your branch based on the newest master? I hope it might help :) Best, scyzoryck. |
@scyzoryck @goetas can this be reviewed / merged? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the code looks good, thanks for contribution! Could you add two missing test scenarios to make sure that we are not missing anything, please?
It would be nice to add new test case for PHPBench to check how it will impact performance of serialisation ;)
Best, Marcin.
Hey @goetas @scyzoryck I've covered changing context in next serialization runs and using context together with naming attributes. Can you review? :) |
@scyzoryck can we push this forward? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dgafka Thanks for changes! I left one additional request. Could you also describe this feature in the docs, please?
@scyzoryck docs updated. cc: |
@scyzoryck thanks for reviewing :) @goetas can we merge this? |
Will fixing the conflicts make it possible to merge? |
Hi! @dgafka - fine for me to merge it :) |
Hey @scyzoryck, PR rebased and green :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Great coverage with tests, no impact on the performance. 👍
I left 2 small comments :)
$cloned = clone $propertyMetadata; | ||
$cloned->setter = null; | ||
$this->accessor->setValue($object, $cloned->defaultValue, $cloned, $this->context); | ||
if (true === $contextSpecificMetadata->hasDefault) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid it can has some side effects if $this->context->getPropertyNamingStrategy()
is null as we are not going to clone at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah true. Should we clone always or leave this part code as it was before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would left it as it used to be :)
/** | ||
* @var string|null | ||
*/ | ||
public $preContextSerializedName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be not used anymore.
Just in general I wonder about use case that it would solve - I do not know so many cases when it would require dynamic change during of the (de-)serialisation naming. On the other hand generating name of the function was one of the biggest performance updates when migration from 1.x to 2.x so using this feature might cause some performance issues. ;-) |
The feature is opt-in, so should not affect current usage if I am not mistaken? And the use case is to use same JMS instance for two different purposes, like serialization of API responses (camel cases needed) and to do Database Mapping (snake cases needed). |
Yes it is optin - so only performance impact will be with custom naming strategy.
When I was taking another look I spotted another potential issue - when passing it into context it overrides all names - also the name defined in attribute/annotation. This behaviour is different than the default one - so it can potential source of the issues for other users. :( |
The configuration will stay the same, so that's fine. I've checked how much bootstrapping ( I may hack my way around, and try to bootstrap them conditionally depending on the usage. This is not ideal but at least there wouldn't be bootstraping penalty. |
With following bench added:
Results on my local was:
So the difference seems to be around 15% ;-) |
This introduces possibility to set custom naming strategy for given serialization/deserialization using SerializationContext.