4371 shaares
We had an issue with a SpringBoot web app where we had the following error message when querying /manage/beans
Could not write JSON Attempted to serialize java.lang.Class Forgot to register a type adapter?
This was due to org.springframework.boot.actuate.beans.BeansEndpoint.BeanDescriptor having a java.lang.Class<?>
attribute.
We fixed it by configuring our Gson bean this way :
@Bean
public static Gson gson() {
return new GsonBuilder()
...
.addSerializationExclusionStrategy(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes field) {
return field.getDeclaredType().getTypeName().equals("java.lang.Class<?>");
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
})
.create();
}