Class ServiceResult<T>
java.lang.Object
com.serinity.accesscontrol.dto.ServiceResult<T>
- Type Parameters:
T- the type of the optional payload
Generic wrapper for service-layer operation results.
Encapsulates a success/failure status, a human-readable message, and an optional payload. Using this DTO instead of raw exceptions keeps controller logic clean and avoids propagating checked exceptions across layers.
ServiceResult<User> result = UserService.signIn(email, password);
if (result.isSuccess()) {
User user = result.getData();
} else {
System.err.println(result.getMessage());
}
- Since:
- 2026-02-03
- Version:
- 1.0
- Author:
- @ZouariOmar (zouariomar20@gmail.com)
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ServiceResult<T> Creates a failure result with an error message and no payload.getData()Returns the optional result payload.Returns the human-readable result message.booleanReturns whether the operation succeeded.static <T> ServiceResult<T> Creates a successful result with a payload and a message.
-
Method Details
-
success
Creates a successful result with a payload and a message.- Type Parameters:
T- the payload type- Parameters:
data- the operation result data (may benull)message- a human-readable success message- Returns:
- a successful
ServiceResult
-
failure
Creates a failure result with an error message and no payload.- Type Parameters:
T- the payload type- Parameters:
message- a human-readable error message- Returns:
- a failed
ServiceResult
-
isSuccess
public boolean isSuccess()Returns whether the operation succeeded.- Returns:
trueif the operation was successful
-
getMessage
Returns the human-readable result message.- Returns:
- success or error message
-
getData
Returns the optional result payload.- Returns:
- the payload, or
nullfor failure results
-