rdabrowski
rdabrowski

Reputation: 404

No serializer found for class java.util.logging.ErrorManager and no properties discovered to create BeanSerializer

I have a problem with serializing a response in REST application.

Here's quick snapshot of my code: ResponseWrapper.class

@JsonInclude(Include.NON_NULL) 
public class ResponseWrapper {

     private User user;
     private Token token;
     private Authentication authentication;

     public ResponseWrapper(){}
     //setters and getters
}

Configuration.class

@Configuration
public class BeanConfig {

@Bean
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode =    ScopedProxyMode.TARGET_CLASS) 
public ResponseWrapper response() {
    return new ResponseWrapper();
}   

}

In my implementation class i got a autowired variable:

@Autowired
ResponseWrapper response;

When i returning my response just like

return response;

i got a message

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: No serializer found for class java.util.logging.ErrorManager and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.coig.prek.webservice.utils.wrappers.ResponseWrapper$$EnhancerBySpringCGLIB$$9e771672["targetSource"]->org.springframework.aop.target.SimpleBeanTargetSource["beanFactory"]->org.springframework.beans.factory.support.DefaultListableBeanFactory["beanClassLoader"]->org.apache.catalina.loader.ParallelWebappClassLoader["resources"]->org.apache.catalina.webresources.StandardRoot["context"]->org.apache.catalina.core.StandardContext["logger"]->org.apache.juli.logging.DirectJDKLog["logger"]->java.util.logging.Logger["parent"]->java.util.logging.Logger["parent"]->java.util.logging.Logger["parent"]->java.util.logging.Logger["handlers"]->org.apache.juli.AsyncFileHandler["errorManager"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.util.logging.ErrorManager and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.coig.prek.webservice.utils.wrappers.ResponseWrapper$$EnhancerBySpringCGLIB$$9e771672["targetSource"]->org.springframework.aop.target.SimpleBeanTargetSource["beanFactory"]->org.springframework.beans.factory.support.DefaultListableBeanFactory["beanClassLoader"]->org.apache.catalina.loader.ParallelWebappClassLoader["resources"]->org.apache.catalina.webresources.StandardRoot["context"]->org.apache.catalina.core.StandardContext["logger"]->org.apache.juli.logging.DirectJDKLog["logger"]->java.util.logging.Logger["parent"]->java.util.logging.Logger["parent"]->java.util.logging.Logger["parent"]->java.util.logging.Logger["handlers"]->org.apache.juli.AsyncFileHandler["errorManager"])

And I actually have no idea what I am doing wrong. I tried to @JsonIgnore annotation with @JsonPropertybut it was no diffrence i working. So I am asking you, what I am doing wrong, that it won't serializable correctly?

If the description is not enough, sorry, I don't know what else I could write about this problem.

@Edit I am returning response bean using ResponseEntity class

return new ResponseEntity<ResponseWrapper>(response, HttpStatus.OK);

Upvotes: 2

Views: 12342

Answers (1)

Sachin Gupta
Sachin Gupta

Reputation: 8368

I think here, jackson is trying to serialize an empty object. You need to configure jackson to avoid this thing:

jackson 1.x:

myObjectMapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);

jackson 2.X

myObjectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

An example to do this thing in Spring can be found here

Upvotes: 1

Related Questions