Created
January 6, 2022 15:49
-
-
Save Kwonkyu/ab6f9b949e5250f17e476ac408a0b990 to your computer and use it in GitHub Desktop.
api response for general rest controller response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import lombok.AllArgsConstructor; | |
| import lombok.Getter; | |
| @Getter | |
| @AllArgsConstructor | |
| public class ApiResponse <T> { | |
| private final boolean success; | |
| private final T result; | |
| private final String message; | |
| public static <U> ApiResponse<U> success(U result) { | |
| return new ApiResponse<>(true, result, ""); | |
| } | |
| public static <U> ApiResponse<U> success(U result, String message) { | |
| return new ApiResponse<>(true, result, message); | |
| } | |
| public static <U> ApiResponse<U> fail(String message) { | |
| return new ApiResponse<>(false, null, message); | |
| } | |
| public static <U> ApiResponse<U> fail(U result, String message) { | |
| return new ApiResponse<>(false, result, message); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment