没有找到类java.util.logging.ErrorManager的序列化器,也没有发现创建BeanSerializer的属性 [英] No serializer found for class java.util.logging.ErrorManager and no properties discovered to create BeanSerializer

查看:1593
本文介绍了没有找到类java.util.logging.ErrorManager的序列化器,也没有发现创建BeanSerializer的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在REST应用程序中序列化响应时遇到问题.

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

这是我的代码的快速快照: ResponseWrapper.class

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.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;

我收到一条消息

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"])

我实际上不知道我在做什么错.我尝试使用@JsonProperty进行@JsonIgnore批注,但是我的工作没有什么区别.所以我问你,我做错了什么,它将无法正确序列化?

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.

@编辑 我正在使用ResponseEntity类返回响应bean

@Edit I am returning response bean using ResponseEntity class

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

推荐答案

我认为在这里,杰克逊(Jackson)试图序列化一个空对象. 您需要配置杰克逊以避免这种情况:

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

杰克逊1.x:

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

jackson 2.X

jackson 2.X

myObjectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

可以找到在Spring中执行此操作的示例

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

这篇关于没有找到类java.util.logging.ErrorManager的序列化器,也没有发现创建BeanSerializer的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆