我在 REST 应用程序中序列化响应时遇到问题。
这是我的代码的快速快照:
ResponseWrapper.class
@JsonInclude(Include.NON_NULL)
public class ResponseWrapper {
private User user;
private Token token;
private Authentication authentication;
public ResponseWrapper(){}
//setters and getters
}
配置类
@Configuration
public class BeanConfig {
@Bean
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
public ResponseWrapper response() {
return new ResponseWrapper();
}
}
在我的实现类中,我得到了一个自动装配变量:
@Autowired
ResponseWrapper response;
当我回复我的回复时,就像
return response;
我收到一条消息
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"])
我实际上不知道我做错了什么。我尝试过了@JsonIgnore
注释与@JsonProperty
但我工作并没有什么区别。所以我问你,我做错了什么,它不能正确序列化?
如果描述不够,抱歉,我不知道我还能写些什么来解决这个问题。
@编辑
我正在使用 ResponseEntity 类返回响应 bean
return new ResponseEntity<ResponseWrapper>(response, HttpStatus.OK);