79
79
*/
80
80
public class ResponseEntity <T > extends HttpEntity <T > {
81
81
82
- private final Object status ;
82
+ private final HttpStatusCode status ;
83
83
84
84
85
85
/**
@@ -108,16 +108,6 @@ public ResponseEntity(MultiValueMap<String, String> headers, HttpStatusCode stat
108
108
this (null , headers , status );
109
109
}
110
110
111
- /**
112
- * Create a {@code ResponseEntity} with a body, headers, and a status code.
113
- * @param body the entity body
114
- * @param headers the entity headers
115
- * @param status the status code
116
- */
117
- public ResponseEntity (@ Nullable T body , @ Nullable MultiValueMap <String , String > headers , HttpStatusCode status ) {
118
- this (body , headers , (Object ) status );
119
- }
120
-
121
111
/**
122
112
* Create a {@code ResponseEntity} with a body, headers, and a raw status code.
123
113
* @param body the entity body
@@ -126,16 +116,20 @@ public ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String>
126
116
* @since 5.3.2
127
117
*/
128
118
public ResponseEntity (@ Nullable T body , @ Nullable MultiValueMap <String , String > headers , int rawStatus ) {
129
- this (body , headers , ( Object ) rawStatus );
119
+ this (body , headers , HttpStatusCode . valueOf ( rawStatus ) );
130
120
}
131
121
132
122
/**
133
- * Private constructor.
123
+ * Create a {@code ResponseEntity} with a body, headers, and a status code.
124
+ * @param body the entity body
125
+ * @param headers the entity headers
126
+ * @param statusCode the status code
134
127
*/
135
- private ResponseEntity (@ Nullable T body , @ Nullable MultiValueMap <String , String > headers , Object status ) {
128
+ public ResponseEntity (@ Nullable T body , @ Nullable MultiValueMap <String , String > headers , HttpStatusCode statusCode ) {
136
129
super (body , headers );
137
- Assert .notNull (status , "HttpStatusCode must not be null" );
138
- this .status = status ;
130
+ Assert .notNull (statusCode , "HttpStatusCode must not be null" );
131
+
132
+ this .status = statusCode ;
139
133
}
140
134
141
135
@@ -144,12 +138,7 @@ private ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String>
144
138
* @return the HTTP status as an HttpStatus enum entry
145
139
*/
146
140
public HttpStatusCode getStatusCode () {
147
- if (this .status instanceof HttpStatusCode statusCode ) {
148
- return statusCode ;
149
- }
150
- else {
151
- return HttpStatusCode .valueOf ((Integer ) this .status );
152
- }
141
+ return this .status ;
153
142
}
154
143
155
144
/**
@@ -161,12 +150,7 @@ public HttpStatusCode getStatusCode() {
161
150
*/
162
151
@ Deprecated (since = "6.0" )
163
152
public int getStatusCodeValue () {
164
- if (this .status instanceof HttpStatusCode statusCode ) {
165
- return statusCode .value ();
166
- }
167
- else {
168
- return (Integer ) this .status ;
169
- }
153
+ return getStatusCode ().value ();
170
154
}
171
155
172
156
@@ -530,14 +514,20 @@ public interface BodyBuilder extends HeadersBuilder<BodyBuilder> {
530
514
531
515
private static class DefaultBuilder implements BodyBuilder {
532
516
533
- private final Object statusCode ;
517
+ private final HttpStatusCode statusCode ;
534
518
535
519
private final HttpHeaders headers = new HttpHeaders ();
536
520
537
- public DefaultBuilder (Object statusCode ) {
521
+
522
+ public DefaultBuilder (int statusCode ) {
523
+ this (HttpStatusCode .valueOf (statusCode ));
524
+ }
525
+
526
+ public DefaultBuilder (HttpStatusCode statusCode ) {
538
527
this .statusCode = statusCode ;
539
528
}
540
529
530
+
541
531
@ Override
542
532
public BodyBuilder header (String headerName , String ... headerValues ) {
543
533
for (String headerValue : headerValues ) {
0 commit comments