package org.example.common; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.io.Serializable; @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) public class ServerResponse extends Object implements Serializable { private int status; private String msg; private T data; private ServerResponse(int status) { this.status = status; } private ServerResponse(int status, T data) { this.status = status; this.data = data; } private ServerResponse(int status, String msg) { this.status = status; this.msg = msg; } private ServerResponse(int status, String msg, T data) { this.status = status; this.msg = msg; this.data = data; } public static void main(String[] args) { ServerResponse serverResponse = new ServerResponse(1, new Object()); ServerResponse serverResponse1 = new ServerResponse(1, "abc"); System.out.print("ServerResponse"); } @JsonIgnore public boolean isSuccess() { return (this.status == ResponseCode.SUCCESS.getCode()); } public int getStatus() { return this.status; } public T getData() { return (T) this.data; } public void setData(T data) { this.data = data; } public String getMsg() { return this.msg; } public static ServerResponse createBySuccess() { return new ServerResponse(ResponseCode.SUCCESS.getCode()); } public static ServerResponse createBySuccessMsg(String msg) { return new ServerResponse(ResponseCode.SUCCESS.getCode(), msg); } public static ServerResponse createBySuccess(T data) { return new ServerResponse(ResponseCode.SUCCESS.getCode(), data); } public static ServerResponse createBySuccess(String msg, T data) { return new ServerResponse(ResponseCode.SUCCESS.getCode(), msg, data); } public static ServerResponse createByError(String msg, T data) { return new ServerResponse(ResponseCode.ERROR.getCode(), msg, data); } public static ServerResponse createByError() { return new ServerResponse(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getMsg()); } public static ServerResponse createByErrorMsg(String errormsg) { return new ServerResponse(ResponseCode.ERROR.getCode(), errormsg); } public static ServerResponse createByErrorCodeMsg(int errorcode, String errormsg) { return new ServerResponse(errorcode, errormsg); } }