-
Notifications
You must be signed in to change notification settings - Fork 570
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
Generate static factory method for generated builders in Java #3073
Comments
Is there something we can improve on |
@oldergod So, currently mapstruct does following steps when trying to generate a mapping:
So, first it tries to find a I tested the solution to work correctly in another project already by manually editing the generated messages. |
Got it, thank you. I didn't know what MapStruct is. I don't think it's such a good idea for Wire to do that, specially since the Builder has a public constructor. Could you reach out to MapStruct and ask for them a hint? Maybe there's a way for you to point out which constructor to use or they could add a new place where they'd be searching for builders as an inner class called |
@oldergod As indicated by the documentation, there is indeed a way to point out which constructor to use, by annotating the constructor with @default
I felt like that would be a less graceful solution than just adding the static builder factory method, as it's a commonly used design pattern. |
@rmschots I don't like having multiple APIs doing the same thing. We have |
When mapping to the generated Java classes for the messages with MapStruct, it is complaining about ambiguous constructors.
It would be able to use the builder if there is a static factory method for it.
I know that this is not a issue with Wire, but rather with mapstruct..
..but it's not really a bad practice to have this design pattern in the generated code, so I'd request it to be added (maybe as an option?) to generate something like this for each message:
This issue prevents me from using Wire in my project.
The text was updated successfully, but these errors were encountered: