Open lombokissues opened 9 years ago
:bust_in_silhouette: b.trafficlight :clock8: Sep 22, 2014 at 17:48 UTC
What steps will reproduce the problem?
What is the expected output? What do you see instead?
It would be cool if @ NoArgsConstructor had an attribute which forced a constructor to initialize all final fields with null.
Currently to support Spring/Hibernate entities one needs to write @ RequiredArgsConstructor and then rudimentary:
MyClass() { this(null, null, null); }
...which is a boilerplate code - Lombok's specialization.
What version of the product are you using? On what operating system?
1.12, RHEL5
Please provide any additional information below.
Something like this?
@ NoArgsConstructor(nullFinalFields=true)
:bust_in_silhouette: r.spilker :clock8: Jan 21, 2015 at 01:19 UTC
There's no need for a nullFinalFields parameter; if you explicitly ask for a NoArgsConstructor while there are uninitialized final fields we can safely assume your code won't compile unless we set the fields to null.
End of migration
Hi! Is there any news?
I'm also interested in this feature. My case: Spring REST
, some DTO
with (public) final
fields. De-serialization is carried out by Jackson
. He access fields via reflections so he can set values for my final
fields. Second usage of my DTOs is to create it manually via "all-args" constructor, but Jackson can't use it without specifying each properties (I don't want write it and lombok can't generate it so that option is not acceptable). Because of it I want to use "no-args" constructor for Jackson and "all-args" for myself, but I can't use @NoArgsConstructor
-- final
fields remains uninitialized.
we can safely assume your code won't compile unless we set the fields to null
And for that reason we need "no-args" constructor which will set null
s to final
fields! 👓
Migrated from Google Code (issue 737)