Skip to content

Potential issues of @Data annotation in dto. #4

@jasper-oh

Description

@jasper-oh
Screenshot 2023-07-10 at 11 39 27 PM

@DaTa is a powerful annotation that includes @tostring, @EqualsAndHashCode, @Getter, @Setter, and @requiredargsconstructor. As a powerful annotation, it also comes with several side effects.

Here are some potential issues that can arise from using @DaTa:

Excessive use of Setter methods:
Setters may be used excessively, leading to unclear intentions and making it difficult to guarantee the object's safety as the state can be changed at any time.
By avoiding unnecessary mutation points, you can ensure stability.

@tostring: Circular reference in bidirectional associations:
Let's consider a situation where Member and Coupon are mapped in a one-to-many bidirectional association.
When calling ToString, it can result in an infinite loop due to circular referencing.

To address this issue, you can use the annotation as follows: @tostring(exclude = "coupons") to exclude specific fields.

@EqualsAndHashCode:
@EqualsAndHashCode generates high-quality equals() and hashCode() methods. While it can be beneficial when used properly, overusing it can lead to serious issues.
One particular concern is when it is applied to mutable objects without any parameters.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions