【发布时间】:2016-09-25 02:16:22
【问题描述】:
当我尝试使用 RESTEasy 检索数据时,出现以下异常:
原因:org.codehaus.jackson.map.JsonMappingException:否 为类找到序列化程序 org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 并且没有 发现创建 BeanSerializer 的属性(为了避免异常, 禁用 SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) )(通过 参考链: les.core.modules.profile.Profile["emails"]->org.hibernate.collection.internal.PersistentSet[0]->mapping.social.employee.email.Email["state"]->mapping.system。 enums.DataState_$$_javassist_172["handler"])
我在互联网上查看并发现,那是因为杰克逊试图序列化尚未加载的数据(尚未加载)。我在某处发现了通过使用这样的杰克逊配置来禁用异常的可能性:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
public class JacksonConfig extends JacksonJsonProvider {
public JacksonConfig() {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
// setMapper(mapper);
}
}
但我不知道如何使它工作,我的意思是,方法setMapper 应该如何?我没有使用弹簧。我还尝试使用以下注释“电子邮件”类
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
它没有帮助。我不想用'@JsonProperty'左右注释每个getter,我真的很想使用配置类禁用这个异常。
这是我的依赖项:
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.0.4.Final</version>
</dependency>
</dependencies>
【问题讨论】:
标签: json hibernate jackson resteasy