-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWyplResponseEntity.java
48 lines (36 loc) · 1.34 KB
/
WyplResponseEntity.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
package com.wypl.applicationcommon;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Getter;
public class WyplResponseEntity<T> extends ResponseEntity<WyplResponseEntity.WyplBody<T>> {
@Builder
public WyplResponseEntity(T body, String message, HttpStatusCode status) {
super(new WyplBody<>(body, message), status);
}
public static <T> WyplResponseEntity<T> ok(T body, String message) {
return new WyplResponseEntity<>(body, message, HttpStatus.OK);
}
public static <T> WyplResponseEntity<T> ok(String message) {
return new WyplResponseEntity<>(null, message, HttpStatus.OK);
}
public static <T> WyplResponseEntity<T> created(T body, String message) {
return new WyplResponseEntity<>(body, message, HttpStatus.CREATED);
}
public static <T> WyplResponseEntity<T> created(String message) {
return new WyplResponseEntity<>(null, message, HttpStatus.CREATED);
}
@Getter
protected static class WyplBody<T> {
@JsonInclude(JsonInclude.Include.NON_NULL)
private final T body;
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String message;
protected WyplBody(T body, String message) {
this.body = body;
this.message = message;
}
}
}