-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Actuator Health web endpoint broken with Gson and Java 17 #34030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report but Actuator requires Jackson and we do not support the use of Gson to serialize Actuator responses to json. There's some more information in #13766. In that issue, @philwebb wondered if we should fail hard when an attempt is made to use Gson:
Perhaps we need to consider that again? It may be too late to make that change in 2.7.x and the benefit would be less in 3.0 as Actuator now has its own, isolated |
Okay, good to know - it's a bit surprising when an "innocent" supported config breaks support elsewhere, and the dependency on Jackson is not really clear from the outside, but glad that this is resolved in 3.x. Any way that I can tell Actuator in 2.7.x to use Jackson in the meantime, while keeping Gson in my production endpoints? I'm using a separate port for management if that makes any difference. |
Hm, from the bug you referenced:
That's not what I am observing right now. All we are doing is this in application.yaml spring:
mvc:
converters:
preferred-json-mapper: gson and in code: @Configuration
public class WebMvcConfig {
@Bean
public GsonBuilderCustomizer gsonCustomizer() {
return gsonBuilder -> {
//custom type mappers
};
}
} Jackson is present in the build, but Actuator seems to use the main GsonHttpMessageConverter with this config. |
@wilkinsona the revert happened after the M2 release, so we left the issue in place as M2 really contains that change. |
We're going to look to see if we can add a DTO so that Jackson and GSON will both work. We're not going to attempt to support all actuator endpoints with GSON, but we can at least try to make health work again. |
I found a way to revert the changes in |
…ot-starter-parent from 2.7.8 to 2.7.9 (patch) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [org.springframework.boot:spring-boot-starter-parent](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | parent | patch | `2.7.8` -> `2.7.9` | --- ### Release Notes <details> <summary>spring-projects/spring-boot</summary> ### [`v2.7.9`](https://github.com/spring-projects/spring-boot/releases/tag/v2.7.9) [Compare Source](spring-projects/spring-boot@v2.7.8...v2.7.9) #### 🐞 Bug Fixes - Maven Plugin's PropertiesMergingResourceTransformer closes InputStream when it should not do so [#​34063](spring-projects/spring-boot#34063) - Actuator Health web endpoint broken with Gson and Java 17 [#​34030](spring-projects/spring-boot#34030) - Dependency management for Mongo's Java Driver is incomplete [#​33941](spring-projects/spring-boot#33941) - Using devtools with Reactive application results in slower restarts [#​33855](spring-projects/spring-boot#33855) - Spies are not reset after test execution when using `@SpyBean` [#​33830](spring-projects/spring-boot#33830) - Properties Migrator does not detect properties of Map type that are marked as deprecated [#​27854](spring-projects/spring-boot#27854) #### 📔 Documentation - Updated documentation for `@ConfigurationProperties` bean naming rules [#​34029](spring-projects/spring-boot#34029) - Restore "Use Jedis Instead of Lettuce" how-to documentation [#​33994](spring-projects/spring-boot#33994) - Add Redis application properties example [#​33965](spring-projects/spring-boot#33965) - Use Maven Central for release downloads in CLI installation documentation [#​33962](spring-projects/spring-boot#33962) - Actuator section is missing from documentation overview [#​33932](spring-projects/spring-boot#33932) - Add Javadoc since to OperationParameter.getAnnotation() [#​33914](spring-projects/spring-boot#33914) - Document additional configuration that is required for spring.mvc.throw-exception-if-no-handler-found=true to be effective [#​31660](spring-projects/spring-boot#31660) #### 🔨 Dependency Upgrades - Upgrade to ActiveMQ 5.16.6 [#​34238](spring-projects/spring-boot#34238) - Upgrade to Byte Buddy 1.12.23 [#​34239](spring-projects/spring-boot#34239) - Upgrade to Dropwizard Metrics 4.2.16 [#​34240](spring-projects/spring-boot#34240) - Upgrade to Elasticsearch 7.17.9 [#...
…ot-starter-parent from 2.7.8 to 2.7.9 (patch) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [org.springframework.boot:spring-boot-starter-parent](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | parent | patch | `2.7.8` -> `2.7.9` | --- ### Release Notes <details> <summary>spring-projects/spring-boot</summary> ### [`v2.7.9`](https://github.com/spring-projects/spring-boot/releases/tag/v2.7.9) [Compare Source](spring-projects/spring-boot@v2.7.8...v2.7.9) #### 🐞 Bug Fixes - Maven Plugin's PropertiesMergingResourceTransformer closes InputStream when it should not do so [#​34063](spring-projects/spring-boot#34063) - Actuator Health web endpoint broken with Gson and Java 17 [#​34030](spring-projects/spring-boot#34030) - Dependency management for Mongo's Java Driver is incomplete [#​33941](spring-projects/spring-boot#33941) - Using devtools with Reactive application results in slower restarts [#​33855](spring-projects/spring-boot#33855) - Spies are not reset after test execution when using `@SpyBean` [#​33830](spring-projects/spring-boot#33830) - Properties Migrator does not detect properties of Map type that are marked as deprecated [#​27854](spring-projects/spring-boot#27854) #### 📔 Documentation - Updated documentation for `@ConfigurationProperties` bean naming rules [#​34029](spring-projects/spring-boot#34029) - Restore "Use Jedis Instead of Lettuce" how-to documentation [#​33994](spring-projects/spring-boot#33994) - Add Redis application properties example [#​33965](spring-projects/spring-boot#33965) - Use Maven Central for release downloads in CLI installation documentation [#​33962](spring-projects/spring-boot#33962) - Actuator section is missing from documentation overview [#​33932](spring-projects/spring-boot#33932) - Add Javadoc since to OperationParameter.getAnnotation() [#​33914](spring-projects/spring-boot#33914) - Document additional configuration that is required for spring.mvc.throw-exception-if-no-handler-found=true to be effective [#​31660](spring-projects/spring-boot#31660) #### 🔨 Dependency Upgrades - Upgrade to ActiveMQ 5.16.6 [#​34238](spring-projects/spring-boot#34238) - Upgrade to Byte Buddy 1.12.23 [#​34239](spring-projects/spring-boot#34239) - Upgrade to Dropwizard Metrics 4.2.16 [#​34240](spring-projects/spring-boot#34240) - Upgrade to Elasticsearch 7.17.9 [#...
In Spring Boot Actuator 2.7.8, the Health class got a new field
exception
. This was includes in commit d7852cb as part of #32527.Unfortunately, Gson is not able to serialize exceptions out of the box in Java 17 due to the closed down module system. This leads to the following exception when calling the health actuator REST endpoint:
Actuator should include the appropriate TypeAdapters to serialize Health objects with Gson out of the box by providing an appropriate GsonBuilderCustomizer for
Health
that deals with theexception
property.Alternatively, instead of just fixing this specifically for Health, an adapter for
Throwable
would be great inStandardGsonBuilderCustomizer
, since that can probably be useful in other places as well (e.g. in@ExceptionHandler
methods).Side note: As a workaround, I also tried to set
spring.gson.exclude-fields-without-expose-annotation=true
, but while that avoided the exception, it resulted in an empty object being returned, since the Health object is not annotated for Gson.The text was updated successfully, but these errors were encountered: