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? :) |
scyzoryck
left a comment
There was a problem hiding this comment.
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? :) |
|
@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 :) |
scyzoryck
left a comment
There was a problem hiding this comment.
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.
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.
Ah true. Should we clone always or leave this part code as it was before?
There was a problem hiding this comment.
I would left it as it used to be :)
| /** | ||
| * @var string|null | ||
| */ | ||
| public $preContextSerializedName; |
There was a problem hiding this comment.
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.