Skip to content

Could not write EnvironmentEndpoint bean to JSON (with solution) #11361

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

Closed
yangzii0920 opened this issue Dec 15, 2017 · 1 comment
Closed

Could not write EnvironmentEndpoint bean to JSON (with solution) #11361

yangzii0920 opened this issue Dec 15, 2017 · 1 comment
Labels
status: invalid An issue that we don't feel is valid

Comments

@yangzii0920
Copy link

Spring-Boot Version: 1.5.9 (issue starts with version 1.5.3)

Description:
I want to get a list of endpoints exposed by actuator.
So I created a bean extending AbstractEndpoin. On invoke it returns a List.
Sample code:

@Component
public cluss LustEndpoints extends AbstractEndpoint<List<Endpoint>>{
private List<Endpoint> endpoints;
@Autowired
public ListEndPoints(List<Endpoint> endpoints) {
	super("showendpoints", false, true);
	this.endpoints = endpoints;
}

@Override
public List<Endpoint> invoke() {
	return this.endpoints;
}
}

After startup and hit the /showendpoints of the server, I got a 500 response and the following message. I changed return object to only the EnvironmentEndpoint to make it clear:

"message": "Could not write JSON document: No serializer found for class org.springframework.core.convert.support.DefaultConversionService and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.boot.actuate.endpoint.EnvironmentEndpoint["resolver"]->org.springframework.boot.actuate.endpoint.EnvironmentEndpoint$PlaceholderSanitizingPropertyResolver["conversionService"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.springframework.core.convert.support.DefaultConversionService and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.boot.actuate.endpoint.EnvironmentEndpoint["resolver"]->org.springframework.boot.actuate.endpoint.EnvironmentEndpoint$PlaceholderSanitizingPropertyResolver["conversionService"])"

Compare source code of 1.5.2 and 1.5.3, I found difference between invoke() method implementations. I'm not sure if it's a bug or another way to map it.

Solution:
Without changing anything, suggested by the error message, I disabled SerializationFeature.FAIL_ON_EMPTY_BEANS by setting spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false in properties file.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 15, 2017
@bclozel
Copy link
Member

bclozel commented Dec 15, 2017

This is because in #8282, we introduced a getResolver() method on that class, and Jackson thinks it's a POJO attribute that should be serialized.

Your workaround works, but the bottom line is - you're not supposed to serialize Spring Boot internals as JSON objects - you should at least extract information out of them and use your own DTOs. If you don't, you expose your application to this kind of issue: any change on our side is likely to break your app.

@bclozel bclozel closed this as completed Dec 15, 2017
@bclozel bclozel added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants