Lazy computed title property should be taken into account
Comment From: quaff
thanks for the PR @quaff but what's the rationale behind this?
using the
getTitle()
overthis.title
isn't that much of an improvement because if the field is not set, the getter derives the result from thethis.status
field (namely, the reason phrase of the enum which is constant). sincethis.status
already participates in bothequals()
andhashcode()
, this change doesn't add new information to these methods.it even arguably can make them less performant, because now instead of a simple null equality + int comparison, it adds resolution of an enum from the status code + getting the enum's reason phrase to the mix.
so overall I don't see the benefit of this change.
You can review the test I added, currently the ProblemDetail
is not equal after serialize then deserialize.
The actual use case is:
ResponseEntity<ProblemDetail> resp = this.testRestTemplate.exchange(
RequestEntity.method(HttpMethod.GET, path).header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).build(),
ProblemDetail.class);
ProblemDetail expected = ProblemDetail.forStatusAndDetail(HttpStatus.CONFLICT, "Conflicts arise");
expected.setTitle(HttpStatus.CONFLICT.getReasonPhrase());
expected.setInstance(URI.create(path));
assertThat(resp.getBody()).isEqualTo(expected);
Title must be explicit set before comparison, but it is implicit at server side, that's not idiomatic.