-
Notifications
You must be signed in to change notification settings - Fork 65
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
Support for multiple constructors #102
Comments
At some point Genson was doing it but it led to ambiguous situations where you don't know what constructor to pick. Then I decided on purpose to use only one constructor and don't switch at runtime. Do you have some strong use case/argument for this feature? Perhaps we can find some alternative.
|
I'm using Genson to configure the creation of Java objects similar to how beans are created using Spring XML configuration. There are cases where classes have multiple constructors but with different argument names and types. Maybe we can have an option at |
Are the properties also settable using a setXx method? If so you can just pick one constructor and mark it with JsonCreator annotation. Genson then will use only this constructor and the setters for the other fields. You can also allow deser to private properties, which should work also in the case of final properties. Let me know if any of those would work for you. |
The properties does not have or are not settable using a |
We have the same issue. When Genson selects a constructor then it should at least select one that does not fail. Today it selects one constructor and then fails with NullPointerException if not all arguments are available. |
Initially we had support for multiple constructors, here is why I removed it:
What do you think, especially about point 2? @ErikLundJensen I prefer we first discuss all this a bit before considering an implementation. I am not necessarily against it, but if we do so then it must add very low overhead to the performances. |
Sorry for not returning before. I understand that you want to keep the code smooth and fast. I suggest that I delete my pull request and thereby make sure it is not used by others. Is that Okay? |
I am going to close your PR for now, but again, if this is a feature you strongly need let's discuss it. I am open to consider it :) |
Is it possible to add support for deserializing to a class with multiple constructors where Genson will loop through the possible constructors and choose which one is appropriate based on the matching between JSON properties and constructor arguments?
The text was updated successfully, but these errors were encountered: