Record Class ResponseDto<T>
java.lang.Object
java.lang.Record
com.app.controller.dto.ResponseDto<T>
- Type Parameters:
T
- the type of the data returned in the response- Record Components:
data
- the successful response data, or null if there is an errorerror
- the error message, or null if the request was successful
Generic response wrapper DTO to encapsulate either the successful data
or an error message.
-
Constructor Summary
ConstructorsConstructorDescriptionResponseDto
(String error) Constructs an error response containing an error message.ResponseDto
(T data) Constructs a successful response containing data.ResponseDto
(T data, String error) Creates an instance of aResponseDto
record class. -
Method Summary
Modifier and TypeMethodDescriptiondata()
Returns the value of thedata
record component.final boolean
Indicates whether some other object is "equal to" this one.error()
Returns the value of theerror
record component.final int
hashCode()
Returns a hash code value for this object.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
ResponseDto
Constructs a successful response containing data.- Parameters:
data
- the response data
-
ResponseDto
Constructs an error response containing an error message.- Parameters:
error
- the error message
-
ResponseDto
-
-
Method Details
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
data
-
error
-