Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Allow to denormalize objects that have constructor checks without using constructor #45508

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

Open
wants to merge 2 commits into
base: 7.3
Choose a base branch
from

Conversation

fbiesse
Copy link

@fbiesse fbiesse commented Feb 22, 2022

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR -

In some cases it would be great to be able to denormalize objects without having to pass by the constructor.
In my case, I have Value Objects that perform validations in their constructor. These objects are normalized, json encoded and persisted in a mongodb database.
If the validation rules changed, it is impossible to denormalize some objects because of the constructor checks, even if the properties exists.
This PR allow to use pure property reflection by skiping the constructor even if it is not private.

To allow this you only need to add the new context param create_instance_without_constructor

@carsonbot
Copy link

Hey!

I think @BafS has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@dunglas
Copy link
Member

dunglas commented Apr 19, 2022

I'm not against this feature, but we should stop "polluting" the abstract class. Our long-term goal is to get rid of it. In my opinion, we should finish and merge #38487 first, then add features such as this one as small, single-responsibility classes.

@fbiesse
Copy link
Author

fbiesse commented Apr 19, 2022

Sure, I agree that it would be clearer.
But #38487 is more than one year old and the last activity was on Oct 2021and unfinished, so this "small" feature will maybe wait more than one year before being integrated because of that. It's sad to read.

@dunglas
Copy link
Member

dunglas commented Apr 19, 2022

Any help is welcome to finish #38487.

@fbiesse
Copy link
Author

fbiesse commented May 15, 2022

I have a question. Not about the pull request but more about a way to go faster in my company's project.
I really need that functionality and I'm looking for a workaround.
It looks like I have to wait for #38487 that is untouched since Oct 20, 2020 and still on study. So I can avoid this because I'll be fired of my company if I tell them they have to wait 2 years ton continue the project :D.
I could work with my fork, but it's not a good idea because I don't know if the feature would be integrated in the future and I'll miss possible security fixes.
I think the best option would be to use jms/serializer that allow to do, but I didn't want to multiply serialization systems.
I know it's a limit in opensource projects and new features.
Do you see better options in my case, I'm pretty sure you already had this kind of problems.

Thank you.

@EmilMassey
Copy link

@fbiesse you can always create your own custom normalizer in your application to support your needs. That way you only need to maintain the normalizer instead of the whole fork.

@fabpot fabpot modified the milestones: 6.1, 6.2 May 20, 2022
@Korbeil
Copy link
Contributor

Korbeil commented Jun 10, 2022

I have a question. Not about the pull request but more about a way to go faster in my company's project. I really need that functionality and I'm looking for a workaround. It looks like I have to wait for #38487 that is untouched since Oct 20, 2020 and still on study. So I can avoid this because I'll be fired of my company if I tell them they have to wait 2 years ton continue the project :D. I could work with my fork, but it's not a good idea because I don't know if the feature would be integrated in the future and I'll miss possible security fixes. I think the best option would be to use jms/serializer that allow to do, but I didn't want to multiply serialization systems. I know it's a limit in opensource projects and new features. Do you see better options in my case, I'm pretty sure you already had this kind of problems.

Thank you.

#38487 is somewhat finished for what I could do, the remaining issue is linked to #38487 (comment), if you can find a solution the PR will be unblocked, but there is not much to change appart from that.

@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@fbiesse
Copy link
Author

fbiesse commented Jun 10, 2023

I just don't want to finish #38487 for my simple need. For me it's out of the context of this PR.

@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@GromNaN
Copy link
Member

GromNaN commented Jul 15, 2024

#38487 have been closed. Is there any interest in updating this PR?

Automapper allows skipping the constructor using #[Mapper(constructorStrategy: ConstructorStrategy::NEVER)]. That can be considered as an alternative solution.

@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants