-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Immutability #149
Comments
Hi @lorenzleutgeb |
You're right. I might do it, but not today... |
Maybe we could simply make an immutable copy of the collection at construction time? |
@joffrey-bion it would be interesting to see benchmarks, this is certainly not the first time someone ha to make this decision... My uneducated guess would be to favour eager duplication in the constructor, because that would already break even in the case where every property is accessed at least once, right? |
I'm mostly looking for setter-less DTO's first, not too worried about the Array itself |
though maybe this code generator, could integrate with another code generator like immutables, don't know if that's possible. |
Since this project already depends on Lombok, I quickly checked whether Lombok's |
@xenoterracide Yeah I wouldn't worry too much about defensive copies of collections, either. @lorenzleutgeb Just to clarify a bit, the fact that this project depends on Lombok should be irrelevant, because we're talking about the generated code that will belong to the target project. |
Yeah I'm aware. I didn't mean to suggest to generate code with Lombok annotations, but to generate code that is essentially equivalent to what Lombok would generate if |
@lorenzleutgeb Yes, I was just answering the first part of your comment. But I agree with you on your conclusion ;) |
Hey, @lorenzleutgeb |
Yeah, I'd do it if you drop the requirement of instantiating unmodifiable collections and instead allow me to do it "the Lombok way", effectively just dropping setters but not having special getter implementations. |
I am fine with Lombok approach |
In order to avoid changes later on, let's also fix the "user interface": How would you like the configuration parameter to be called? I'd call it |
How about ‘generateImmutableModels’ or ‘generateModelsImmutable’? |
I think that |
Just to confirm: Starting from version 2, together with the feature described in #148, MapStruct can now target immutable DTOs and will instantiate them via the builder 🎊 |
I'd like the DTOs generated by
graphql-java-codegen
to optionally be "immutable".By "immutable" I mean that the generated classes do not have any setters. Very similar to to what Lombok does with its
@Value
annotation.A generated class with this feature enabled should look like:
If you approve the addition of this feature, I am happy to implement and PR it.
The text was updated successfully, but these errors were encountered: