Skip to content

Instantly share code, notes, and snippets.

@Kwonkyu
Created January 6, 2022 15:49
Show Gist options
  • Save Kwonkyu/ab6f9b949e5250f17e476ac408a0b990 to your computer and use it in GitHub Desktop.
Save Kwonkyu/ab6f9b949e5250f17e476ac408a0b990 to your computer and use it in GitHub Desktop.

Revisions

  1. Kwonkyu created this gist Jan 6, 2022.
    26 changes: 26 additions & 0 deletions ApiResponse.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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);
    }
    }