Skip to content
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

Spring Boot Actuator dependency on Jackson prevents usage of GSON #2247

Closed
laurikimmel opened this issue Dec 28, 2014 · 8 comments
Closed

Spring Boot Actuator dependency on Jackson prevents usage of GSON #2247

laurikimmel opened this issue Dec 28, 2014 · 8 comments
Labels
type: blocker An issue that is blocking us from releasing type: enhancement A general enhancement
Milestone

Comments

@laurikimmel
Copy link

According to Spring Boot 1.2.0 release notes all Jackson libraries has to be excluded from the classpath to use GSON for creating JSON output. This is not possible in case application is using spring-boot-starter-actuator.

Excluding jackson-core, jackson-databind and jackson-annotations from spring-boot-starter-actuator will result with BeanCreationException:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesReportEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpoint]: Factory method 'configurationPropertiesReportEndpoint' threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/AnnotationIntrospector

And the application is not able to start.

It turns out spring-boot-starter-actuator needs all three mentioned Jackson libraries to start properly. Once Jackson libraries are included in the classpath GSON is not used to produce JSON output any more.

@snicoll
Copy link
Member

snicoll commented Dec 28, 2014

I don't think that's what the release notes is saying. Are you trying to use GSON for everything or your own services only?

@laurikimmel
Copy link
Author

Spring Boot 1.2 Release Notes:

It is now possible to use GSON instead of Jackson to create JSON output. If you use GSON you should exclude Jackson libraries from your Maven/Gradle build. Jackson remains the default and recommended choice.

I was investigating how to use GSON for my own services. Release notes where only documentation I was able to find about Spring Boot and GSON support.

@philwebb philwebb added the type: bug A general bug label Dec 28, 2014
@philwebb philwebb added this to the 1.2.1 milestone Dec 28, 2014
@philwebb
Copy link
Member

Looks like this one might be a little tricky to fix. The easiest solution for now might be for us to disable that endpoint if Jackson is missing or find some way to allow them to co-exist.

@snicoll
Copy link
Member

snicoll commented Dec 28, 2014

My point was that the release notes are only about what Boot uses internally. You can still configure and use Gson if that's what you want to do.

@philwebb philwebb modified the milestones: 1.2.2, 1.2.1 Jan 6, 2015
@dsyer
Copy link
Member

dsyer commented Jan 9, 2015

I guess we need a way to tell the autoconfigurers that even if they find Jackson and GSON, we prefer GSON. I think the user can always create converters and assign an order using HttpMessageConverters though, so there isn't anything stopping you from using GSON (hence I don't think this is a bug).

@wilkinsona wilkinsona added type: enhancement A general enhancement and removed type: bug A general bug labels Feb 4, 2015
@philwebb philwebb reopened this Feb 4, 2015
@philwebb philwebb added the type: blocker An issue that is blocking us from releasing label Feb 4, 2015
@philwebb
Copy link
Member

philwebb commented Feb 4, 2015

Reopening to consider comments in commit d718a80

wilkinsona added a commit that referenced this issue Feb 5, 2015
preferred-mapper has been renamed to preferred-json-mapper to make it
clear that it only affects the JSON mapper and that the XML mapper
that will be used (if any) is unaffected

See gh-2247
@balajeetm
Copy link

Is there a way to use Gson only for specific classes - mainly (JsonElement, JsonObject, JsonArray) and for the rest use Jackson. JsonElement is not a plain pojo, hence jackson has trouble serialising it. Would be good if we can use both or if actuator can work with Gson. How should we go about it?

@philwebb
Copy link
Member

philwebb commented Oct 6, 2016

@balajeetm This issue has been closed for a while. If you've got additional questions please ask on stackoverflow.com. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: blocker An issue that is blocking us from releasing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

6 participants