File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
main/java/org/springframework/http
test/java/org/springframework/http Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 42
42
*
43
43
* @author Rossen Stoyanchev
44
44
* @author Juergen Hoeller
45
+ * @author Yanming Zhou
45
46
* @since 6.0
46
47
* @see <a href="https://datatracker.ietf.org/doc/html/rfc7807">RFC 7807</a>
47
48
* @see org.springframework.web.ErrorResponse
@@ -239,7 +240,7 @@ public boolean equals(@Nullable Object other) {
239
240
return false ;
240
241
}
241
242
return (this .type .equals (otherDetail .type ) &&
242
- ObjectUtils .nullSafeEquals (this .title , otherDetail .title ) &&
243
+ ObjectUtils .nullSafeEquals (this .getTitle () , otherDetail .getTitle () ) &&
243
244
this .status == otherDetail .status &&
244
245
ObjectUtils .nullSafeEquals (this .detail , otherDetail .detail ) &&
245
246
ObjectUtils .nullSafeEquals (this .instance , otherDetail .instance ) &&
@@ -249,7 +250,7 @@ public boolean equals(@Nullable Object other) {
249
250
@ Override
250
251
public int hashCode () {
251
252
int result = this .type .hashCode ();
252
- result = 31 * result + ObjectUtils .nullSafeHashCode (this .title );
253
+ result = 31 * result + ObjectUtils .nullSafeHashCode (this .getTitle () );
253
254
result = 31 * result + this .status ;
254
255
result = 31 * result + ObjectUtils .nullSafeHashCode (this .detail );
255
256
result = 31 * result + ObjectUtils .nullSafeHashCode (this .instance );
Original file line number Diff line number Diff line change 16
16
17
17
package org .springframework .http ;
18
18
19
+ import com .fasterxml .jackson .databind .ObjectMapper ;
19
20
import org .junit .jupiter .api .Test ;
20
21
21
22
import static org .assertj .core .api .Assertions .assertThat ;
24
25
* Unit tests for {@link ProblemDetail}.
25
26
*
26
27
* @author Juergen Hoeller
28
+ * @author Yanming Zhou
27
29
*/
28
30
class ProblemDetailTests {
29
31
30
32
@ Test
31
- void equalsAndHashCode () {
33
+ void equalsAndHashCode () throws Exception {
32
34
ProblemDetail pd1 = ProblemDetail .forStatus (500 );
33
35
ProblemDetail pd2 = ProblemDetail .forStatus (HttpStatus .INTERNAL_SERVER_ERROR );
34
36
ProblemDetail pd3 = ProblemDetail .forStatus (HttpStatus .NOT_FOUND );
@@ -48,6 +50,12 @@ void equalsAndHashCode() {
48
50
assertThat (pd2 ).isNotEqualTo (pd4 );
49
51
assertThat (pd1 .hashCode ()).isNotEqualTo (pd3 .hashCode ());
50
52
assertThat (pd1 .hashCode ()).isNotEqualTo (pd4 .hashCode ());
53
+
54
+ ObjectMapper om = new ObjectMapper ();
55
+ ProblemDetail pd5 = om .readValue (om .writeValueAsBytes (pd1 ), ProblemDetail .class );
56
+ assertThat (pd1 ).isEqualTo (pd5 );
57
+ assertThat (pd5 ).isEqualTo (pd1 );
58
+ assertThat (pd1 .hashCode ()).isEqualTo (pd5 .hashCode ());
51
59
}
52
60
53
61
}
You can’t perform that action at this time.
0 commit comments