Rework health response structure to eliminate chance of key clashes
Previously, if a health's details contained a key named status (either because an indicator bean was named statusHealthIndicator or an indicator added an entry named status to its details) this would clash with the health's own status as the details were serialized as siblings of the status field. This commit updates Health to remove @JsonAnyGetter from getDetails(). This means that all of a Health's details will now be nested within a separate details field, thereby preventing a possible clash with the status field. Closes gh-10249
This commit is contained in:
parent
bc9d8bb1cf
commit
85493367b6
|
@ -20,7 +20,6 @@ import java.util.Collections;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||
|
@ -80,7 +79,6 @@ public final class Health {
|
|||
* Return the details of the health.
|
||||
* @return the details (or an empty map)
|
||||
*/
|
||||
@JsonAnyGetter
|
||||
public Map<String, Object> getDetails() {
|
||||
return this.details;
|
||||
}
|
||||
|
|
|
@ -49,8 +49,9 @@ public class HealthEndpointWebIntegrationTests {
|
|||
@Test
|
||||
public void whenHealthIsUp200ResponseIsReturned() throws Exception {
|
||||
client.get().uri("/application/health").exchange().expectStatus().isOk()
|
||||
.expectBody().jsonPath("status").isEqualTo("UP").jsonPath("alpha.status")
|
||||
.isEqualTo("UP").jsonPath("bravo.status").isEqualTo("UP");
|
||||
.expectBody().jsonPath("status").isEqualTo("UP")
|
||||
.jsonPath("details.alpha.status").isEqualTo("UP")
|
||||
.jsonPath("details.bravo.status").isEqualTo("UP");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -59,8 +60,8 @@ public class HealthEndpointWebIntegrationTests {
|
|||
.setHealth(Health.down().build());
|
||||
client.get().uri("/application/health").exchange().expectStatus()
|
||||
.isEqualTo(HttpStatus.SERVICE_UNAVAILABLE).expectBody().jsonPath("status")
|
||||
.isEqualTo("DOWN").jsonPath("alpha.status").isEqualTo("DOWN")
|
||||
.jsonPath("bravo.status").isEqualTo("UP");
|
||||
.isEqualTo("DOWN").jsonPath("details.alpha.status").isEqualTo("DOWN")
|
||||
.jsonPath("details.bravo.status").isEqualTo("UP");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
|
@ -120,10 +120,11 @@ public class CompositeHealthIndicatorTests {
|
|||
composite.addHealthIndicator("db", innerComposite);
|
||||
Health result = composite.health();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
assertThat(mapper.writeValueAsString(result))
|
||||
.isEqualTo("{\"status\":\"UNKNOWN\",\"db\":{\"status\":\"UNKNOWN\""
|
||||
+ ",\"db1\":{\"status\":\"UNKNOWN\",\"1\":\"1\"},"
|
||||
+ "\"db2\":{\"status\":\"UNKNOWN\",\"2\":\"2\"}}}");
|
||||
assertThat(mapper.writeValueAsString(result)).isEqualTo(
|
||||
"{\"status\":\"UNKNOWN\",\"details\":{\"db\":{\"status\":\"UNKNOWN\""
|
||||
+ ",\"details\":{\"db1\":{\"status\":\"UNKNOWN\",\"details\""
|
||||
+ ":{\"1\":\"1\"}},\"db2\":{\"status\":\"UNKNOWN\",\"details\""
|
||||
+ ":{\"2\":\"2\"}}}}}}");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue