I think this will be a good feature. I also think it will take some playing with it it learn where the line is where one should switch from record to full class.
I will say, I'm kind of annoyed that they didn't stick to the getFoo() convention for the accessor methods, if only because there are reflection-based libraries out there that expect it — e.g. Jackson for JSON serialization. I assume in Jackson's case they'll have to add special support for records (if they haven't already).
Reflection based libraries can be updated. And once they are, having a reliable list of members and accessors reflected directly as part of the Class API will be way better than relying on convention. I expect libraries like Jackson will welcome this improvement rather than complain.
Plus, the prevalance of getters and setters in general is a blight on the Java ecosystem. Beans are encapsulation-destroying garbage in OOP. Records thankfully say that if you want a simple data carrier then you have to be principled about it and follow some basic rules.
Jackson and others already provide annotations to help them determine what to use and how. Shame that libraries even opt for some convention scanning rather than forcing you to use those annonations.
My preference is for a library that tried to do the right thing by default, and gives you configuration hold to change that. Jackson does that — it scans for the most common convention and then gives you a tremendous amount of flexibility to customize.
For records, though, there's no convention and there's no accessor method to annotate with @JsonProperty("foo"). And I have to flexibility to make the library (JDK) emit the shape I may want — I'm now stuck choosing between the existing convention and this new convention.
As I said in my reply to the comment above, I have no doubt that Jackson and many projects like it will update to look for record metadata using reflection. I'm just saying it sucks to throw out some two decades of convention.
9
u/javajunkie314 Jan 17 '20
I think this will be a good feature. I also think it will take some playing with it it learn where the line is where one should switch from record to full class.
I will say, I'm kind of annoyed that they didn't stick to the
getFoo()convention for the accessor methods, if only because there are reflection-based libraries out there that expect it — e.g. Jackson for JSON serialization. I assume in Jackson's case they'll have to add special support for records (if they haven't already).