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.
api response for general rest controller response
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