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

11,284

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

Share:
11,284

Related videos on Youtube

rdabrowski
Author by

rdabrowski

I am back end developer but I like to perform full-stack stuff. For this moment I have good knowledge about Java, Spring and Spring-Boot. I have basic skills in Angular 2+ and PHP (frameworks like Symphony 3 and CakePHP 3.x). My personal website is here. Greetings!

Updated on June 04, 2022

Comments

  • rdabrowski
    rdabrowski almost 2 years

    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);
    
  • rdabrowski
    rdabrowski over 7 years
    The problem is that when i am doing that i got "Infinite recursion" for some reason. In other hand that serialized object is never empty.
  • Sachin Gupta
    Sachin Gupta over 7 years
    Try to remove Autowired from respone instance.
  • rdabrowski
    rdabrowski over 7 years
    But if I understand it corectly i will not be able to call a instance of that bean
  • Sachin Gupta
    Sachin Gupta over 7 years
    I think response should be created by the code not by the container. So removing it should be good,