projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.85k stars 2.38k forks source link

[FEATURE] Add @ToString support for java records #3404

Open eimmar opened 1 year ago

eimmar commented 1 year ago

Feature Currently using the @ToString annotation on a record results in a error: @ToString is only supported on a class or enum. error. While the record itself generates toString implementation by default, it includes all of it's fields. In cases when such records can include sensitive medical or financial information this behaviour is unacceptable and there is a need to include only a few explicitly included record fields to prevent accidental logging of such information. Having to resort to overriding toString each time is not optimal.

Before the feature:

@Value
@ToString(onlyExplicitlyIncluded = true)
public class PDFObservation {
    @ToString.Include
    String code;
    String resultValue;
    String resultUnit;
}

After the feature:

@ToString(onlyExplicitlyIncluded = true)
public record Observation(@ToString.Include String code, String resultValue, String resultUnit) {}

Target audiance Developers working with systems containing sensitive medical or financial information.

shivu2002a commented 1 year ago

Hi, @eimmar

Can I take up this issue?

eimmar commented 1 year ago

@shivu2002a
Of course.