-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonResponse.java
65 lines (53 loc) · 1.58 KB
/
JsonResponse.java
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
import java.io.Serializable;
/**
* Created with IntelliJ IDEA.
* User: WuYifei
* Date: 2017/7/21
* Time: 17:16
*/
public class JsonResponse<T> implements Serializable {
public static final int RETURN_SUCCESS = 1;
public static final int RETURN_FAILURE = 0;
public static final String error = "{\"returnCode\":0,\"returnMsg\":\"error\"}";
public static final String success = "{\"returnCode\":1,\"returnMsg\":\"success\"}";
private static final long serialVersionUID = 3617154470380165248L;
private int returnCode;
private String returnMsg;
private T content;
public JsonResponse() {
}
public JsonResponse(int returnCode, String returnMsg, T content) {
super();
this.returnCode = returnCode;
this.returnMsg = returnMsg;
this.content = content;
}
public JsonResponse(int returnCode, String returnMsg) {
super();
this.returnCode = returnCode;
this.returnMsg = returnMsg;
}
public int getReturnCode() {
return returnCode;
}
public void setReturnCode(int returnCode) {
this.returnCode = returnCode;
}
public String getReturnMsg() {
return returnMsg;
}
public void setReturnMsg(String returnMsg) {
this.returnMsg = returnMsg;
}
public T getContent() {
return content;
}
public void setContent(T content) {
this.content = content;
}
@Override
public String toString() {
String json = JsonMapper.getDefault().toJson(this);
return json == null ? JsonResponse.error : json;
}
}