|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2020 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | import java.util.LinkedHashMap;
|
21 | 21 | import java.util.Map;
|
22 | 22 |
|
| 23 | +import com.fasterxml.jackson.databind.MapperFeature; |
23 | 24 | import com.fasterxml.jackson.databind.ObjectMapper;
|
24 | 25 | import org.junit.jupiter.api.Test;
|
25 | 26 |
|
@@ -80,4 +81,17 @@ void serializeV2WithJacksonReturnsValidJson() throws Exception {
|
80 | 81 | + "\"db2\":{\"status\":\"DOWN\",\"details\":{\"a\":\"b\"}}}}");
|
81 | 82 | }
|
82 | 83 |
|
| 84 | + @Test // gh-26797 |
| 85 | + void serializeV2WithJacksonAndDisabledCanOverrideAccessModifiersReturnsValidJson() throws Exception { |
| 86 | + Map<String, HealthComponent> components = new LinkedHashMap<>(); |
| 87 | + components.put("db1", Health.up().build()); |
| 88 | + components.put("db2", Health.down().withDetail("a", "b").build()); |
| 89 | + CompositeHealth health = new CompositeHealth(ApiVersion.V2, Status.UP, components); |
| 90 | + ObjectMapper mapper = new ObjectMapper(); |
| 91 | + mapper.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS); |
| 92 | + String json = mapper.writeValueAsString(health); |
| 93 | + assertThat(json).isEqualTo("{\"status\":\"UP\",\"details\":{\"db1\":{\"status\":\"UP\"}," |
| 94 | + + "\"db2\":{\"status\":\"DOWN\",\"details\":{\"a\":\"b\"}}}}"); |
| 95 | + } |
| 96 | + |
83 | 97 | }
|
0 commit comments