I have the following class.
// Adding Lombok's @Data / @Value gives an error
public class Sample {
String id;
String name;
Dummy[] entries;
@JsonCreator
// @Builder --> This gives same error
private Sample(
@JsonProperty("id") final String id,
@JsonProperty("name") final String name,
@JsonProperty("entries") @NonNull final Dummy[] entries) {
this.id = id;
this.name = name;
this.entries = entries;
}
}
If I add Lomobok annotations, I get the following error. We heavily rely on Lombok and I am trying to figure out how I can ensure I don't return a mutable object.
EI_EXPOSE_REP: May expose internal representation by returning reference to mutable object
EI_EXPOSE_REP2: May expose internal representation by incorporating reference to mutable object
As an alternative, I could use List instead of Array and rely on @Singular annotation. But I would like to know if there is a workaround for Array with Lombok's annoations.
getter
for that field on your own by usingArrays.copyOf
. But I'm unsure this will help.