-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonResponse.java
More file actions
102 lines (79 loc) · 2.88 KB
/
Copy pathCommonResponse.java
File metadata and controls
102 lines (79 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.time.Instant;
/**
* Common Format for an unified HTTP Response.
* @author Jason/GeW
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class CommonResponse<T> implements Serializable {
private Integer code;
private Status status;
private String message;
@JsonInclude(JsonInclude.Include.NON_NULL)
private String timestamp;
@JsonInclude(JsonInclude.Include.NON_NULL)
private T result;
private Boolean success
public CommonResponse() {
}
public CommonResponse(T result) {
this.code = 200;
this.status = Status.SUCCESS;
this.message = "Operation Success";
this.result = result;
this.success = true;
this.timestamp = Instant.now().toString();
}
public CommonResponse(Integer code, Status status, String message) {
this.code = code;
this.status = status;
this.message = message;
this.timestamp = Instant.now().toString();
this.success = status == Status.SUCCESS ? true : false;
}
public CommonResponse(Integer code, Status status, String message, T result) {
this.code = code;
this.status = status;
this.message = message;
this.result = result;
this.timestamp = Instant.now().toString();
this.success = status == Status.SUCCESS ? true : false;
}
public CommonResponse(Integer code, Status status, String message, T result, String timestamp) {
this.code = code;
this.status = status;
this.message = message;
this.result = result;
this.timestamp = timestamp;
this.success = status == Status.SUCCESS ? true : false;
}
public Integer getCode() { return code; }
public void setCode(Integer code) { this.code = code; }
public Status getStatus() { return status; }
public void setStatus(Status status) { this.status = status; }
public String getMessage() { return message; }
public void setMessage(String message) { this.message = message; }
public String getTimestamp() { return timestamp; }
public void setTimestamp(String timestamp) { this.timestamp = timestamp; }
public T getResult() { return result; }
public void setResult(T result) { this.result = result; }
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
@Override
public String toString() {
return "CommonResponse{" +
"code=" + code +
", status=" + status +
", message='" + message + '\'' +
", timestamp='" + timestamp + '\'' +
", result=" + result +
", success=" + success +
'}';
}
}