【jackson 异常】com.fasterxml.jackson.databind.JsonMappingException异常处理
项目中,父层是Gene.java【基因实体】 子层是Corlib.java【文集库实体】,一种基因对用多个文集库文章
但是在查询文集库这个实体的时候报错:【com.fasterxml.jackson.databind.JsonMappingException】
com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.agen.entity.Corlib["gene"]->com.agen.entity.Gene_$$_jvstb50_3["handler"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:275)
at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1109)
at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1134)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3672)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3048)
at com.agen.controller.CorlibController.queryAllcorlib(CorlibController.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.agen.util.LoginFilter.doFilter(LoginFilter.java:58)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1778)
at java.lang.Thread.run(Thread.java:745)

错误描述:
Could not write content: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

由于会发生 循环引用的问题,因此在实体中进行了截断即子层可以查到父层的信息,但是父层查不到子层的信息。
解决问题:
Corlib.java的实体类中Gene字段的处理本来是:

将其修改为:

即可!!
附带给上这两个实体的代码:
Gene.java的代码:
package com.agen.entity; import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set; import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /**
* Gene entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "gene", catalog = "biologyinfo")
public class Gene implements java.io.Serializable { // Fields private String geneId;
private Disease disease;
private String geneName;
private String location;
private String snp;
private String position;
private String allele;
private String influence;
private String riskAllele;
private String alleleFrequency;
private String genotypeModel;
private String genotypeFrequency;
private String orhrvalue;
private String minorAllele;
private String caseNum;
private String controlNum;
private String flankingSequence;
private String foreignPublished;
private String hapMap;
private String theE;
private String alterSite;
private String alterSiteRisk;
private String geneCre;
private Timestamp createDate;
private Timestamp updateDate;
private String transPerson;
private Set<Corlib> corlibs = new HashSet<Corlib>(0); // Constructors /** default constructor */
public Gene() {
} /** minimal constructor */
public Gene(Disease disease) {
this.disease = disease;
} /** full constructor */
public Gene(Disease disease, String geneName, String location, String snp,
String position, String allele, String influence,
String riskAllele, String alleleFrequency, String genotypeModel,
String genotypeFrequency, String orhrvalue, String minorAllele,
String caseNum, String controlNum, String flankingSequence,
String foreignPublished, String hapMap, String theE,
String alterSite, String alterSiteRisk, String geneCre,
Timestamp createDate, Timestamp updateDate, String transPerson,
Set<Corlib> corlibs) {
this.disease = disease;
this.geneName = geneName;
this.location = location;
this.snp = snp;
this.position = position;
this.allele = allele;
this.influence = influence;
this.riskAllele = riskAllele;
this.alleleFrequency = alleleFrequency;
this.genotypeModel = genotypeModel;
this.genotypeFrequency = genotypeFrequency;
this.orhrvalue = orhrvalue;
this.minorAllele = minorAllele;
this.caseNum = caseNum;
this.controlNum = controlNum;
this.flankingSequence = flankingSequence;
this.foreignPublished = foreignPublished;
this.hapMap = hapMap;
this.theE = theE;
this.alterSite = alterSite;
this.alterSiteRisk = alterSiteRisk;
this.geneCre = geneCre;
this.createDate = createDate;
this.updateDate = updateDate;
this.transPerson = transPerson;
this.corlibs = corlibs;
} // Property accessors
@GenericGenerator(name = "generator", strategy = "uuid.hex")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "geneID", unique = true, nullable = false, length = 36)
public String getGeneId() {
return this.geneId;
} public void setGeneId(String geneId) {
this.geneId = geneId;
} @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "diseaseId", nullable = false)
public Disease getDisease() {
return this.disease;
} public void setDisease(Disease disease) {
this.disease = disease;
} @Column(name = "geneName", length = 30)
public String getGeneName() {
return this.geneName;
} public void setGeneName(String geneName) {
this.geneName = geneName;
} @Column(name = "location", length = 30)
public String getLocation() {
return this.location;
} public void setLocation(String location) {
this.location = location;
} @Column(name = "SNP", length = 30)
public String getSnp() {
return this.snp;
} public void setSnp(String snp) {
this.snp = snp;
} @Column(name = "position", length = 30)
public String getPosition() {
return this.position;
} public void setPosition(String position) {
this.position = position;
} @Column(name = "allele", length = 30)
public String getAllele() {
return this.allele;
} public void setAllele(String allele) {
this.allele = allele;
} @Column(name = "influence", length = 30)
public String getInfluence() {
return this.influence;
} public void setInfluence(String influence) {
this.influence = influence;
} @Column(name = "riskAllele", length = 3)
public String getRiskAllele() {
return this.riskAllele;
} public void setRiskAllele(String riskAllele) {
this.riskAllele = riskAllele;
} @Column(name = "alleleFrequency", length = 30)
public String getAlleleFrequency() {
return this.alleleFrequency;
} public void setAlleleFrequency(String alleleFrequency) {
this.alleleFrequency = alleleFrequency;
} @Column(name = "genotypeModel", length = 30)
public String getGenotypeModel() {
return this.genotypeModel;
} public void setGenotypeModel(String genotypeModel) {
this.genotypeModel = genotypeModel;
} @Column(name = "genotypeFrequency", length = 30)
public String getGenotypeFrequency() {
return this.genotypeFrequency;
} public void setGenotypeFrequency(String genotypeFrequency) {
this.genotypeFrequency = genotypeFrequency;
} @Column(name = "oRHRvalue", length = 30)
public String getOrhrvalue() {
return this.orhrvalue;
} public void setOrhrvalue(String orhrvalue) {
this.orhrvalue = orhrvalue;
} @Column(name = "minorAllele", length = 30)
public String getMinorAllele() {
return this.minorAllele;
} public void setMinorAllele(String minorAllele) {
this.minorAllele = minorAllele;
} @Column(name = "caseNum", length = 30)
public String getCaseNum() {
return this.caseNum;
} public void setCaseNum(String caseNum) {
this.caseNum = caseNum;
} @Column(name = "controlNum", length = 30)
public String getControlNum() {
return this.controlNum;
} public void setControlNum(String controlNum) {
this.controlNum = controlNum;
} @Column(name = "flankingSequence", length = 300)
public String getFlankingSequence() {
return this.flankingSequence;
} public void setFlankingSequence(String flankingSequence) {
this.flankingSequence = flankingSequence;
} @Column(name = "foreignPublished", length = 30)
public String getForeignPublished() {
return this.foreignPublished;
} public void setForeignPublished(String foreignPublished) {
this.foreignPublished = foreignPublished;
} @Column(name = "hapMap", length = 30)
public String getHapMap() {
return this.hapMap;
} public void setHapMap(String hapMap) {
this.hapMap = hapMap;
} @Column(name = "theE", length = 30)
public String getTheE() {
return this.theE;
} public void setTheE(String theE) {
this.theE = theE;
} @Column(name = "alterSite", length = 30)
public String getAlterSite() {
return this.alterSite;
} public void setAlterSite(String alterSite) {
this.alterSite = alterSite;
} @Column(name = "alterSiteRisk", length = 30)
public String getAlterSiteRisk() {
return this.alterSiteRisk;
} public void setAlterSiteRisk(String alterSiteRisk) {
this.alterSiteRisk = alterSiteRisk;
} @Column(name = "geneCre", length = 500)
public String getGeneCre() {
return this.geneCre;
} public void setGeneCre(String geneCre) {
this.geneCre = geneCre;
} @Column(name = "createDate", length = 19)
public Timestamp getCreateDate() {
return this.createDate;
} public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
} @Column(name = "updateDate", length = 19)
public Timestamp getUpdateDate() {
return this.updateDate;
} public void setUpdateDate(Timestamp updateDate) {
this.updateDate = updateDate;
} @Column(name = "transPerson", length = 36)
public String getTransPerson() {
return this.transPerson;
} public void setTransPerson(String transPerson) {
this.transPerson = transPerson;
} @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "gene")
public Set<Corlib> getCorlibs() {
return this.corlibs;
} public void setCorlibs(Set<Corlib> corlibs) {
this.corlibs = corlibs;
} }
Corlib.java的代码:
package com.agen.entity; import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator; /**
* Corlib entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "corlib", catalog = "biologyinfo")
public class Corlib implements java.io.Serializable { // Fields private String corlibId;
private Gene gene;
private String corlibContext;
private String corlibCre;
private Timestamp createDate;
private Timestamp updateDate;
private String transPerson; // Constructors /** default constructor */
public Corlib() {
} /** minimal constructor */
public Corlib(Gene gene) {
this.gene = gene;
} /** full constructor */
public Corlib(Gene gene, String corlibContext, String corlibCre,
Timestamp createDate, Timestamp updateDate, String transPerson) {
this.gene = gene;
this.corlibContext = corlibContext;
this.corlibCre = corlibCre;
this.createDate = createDate;
this.updateDate = updateDate;
this.transPerson = transPerson;
} // Property accessors
@GenericGenerator(name = "generator", strategy = "uuid.hex")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "corlibId", unique = true, nullable = false, length = 36)
public String getCorlibId() {
return this.corlibId;
} public void setCorlibId(String corlibId) {
this.corlibId = corlibId;
} @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "geneID", nullable = false)
public Gene getGene() {
return this.gene;
} public void setGene(Gene gene) {
this.gene = gene;
} @Column(name = "corlibContext", length = 65535)
public String getCorlibContext() {
return this.corlibContext;
} public void setCorlibContext(String corlibContext) {
this.corlibContext = corlibContext;
} @Column(name = "corlibCre", length = 500)
public String getCorlibCre() {
return this.corlibCre;
} public void setCorlibCre(String corlibCre) {
this.corlibCre = corlibCre;
} @Column(name = "createDate", length = 19)
public Timestamp getCreateDate() {
return this.createDate;
} public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
} @Column(name = "updateDate", length = 19)
public Timestamp getUpdateDate() {
return this.updateDate;
} public void setUpdateDate(Timestamp updateDate) {
this.updateDate = updateDate;
} @Column(name = "transPerson", length = 36)
public String getTransPerson() {
return this.transPerson;
} public void setTransPerson(String transPerson) {
this.transPerson = transPerson;
} }
【jackson 异常】com.fasterxml.jackson.databind.JsonMappingException异常处理的更多相关文章
- SpringBoot JPA懒加载异常 - com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy
问题与分析 某日忽然发现在用postman测试数据时报错如下: com.fasterxml.jackson.databind.JsonMappingException: could not initi ...
- 400 bad Request: JackSon将json串转成List<Object>,异常com.fasterxml.jackson.databind.JsonMappingException
最近遇到的400, 以前总以为 400 就是参数不匹配造成的,直到今天遇到这个问题 控制台报错如下: com.fasterxml.jackson.databind.JsonMappingExcept ...
- com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
作者原创,转载请注明转载地址 第一次遇到该异常,在网上搜了很长时间也没找到解决答案,特此记录 1.异常展示: com.fasterxml.jackson.databind.JsonMappingExc ...
- JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of j
异常信息如下: JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token ...
- com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field 异常
分享牛原创(尊重原创 转载对的时候第一行请注明,转载出处来自分享牛http://blog.csdn.net/qq_30739519) 1.1.1. 前言 近期在使用ObjectMapper对象将jso ...
- HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite
org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite r ...
- JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc
代码程序: @PostMapping("selectById") @ResponseBody public Result selectById(@RequestBody int i ...
- java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
RabbitMq配置时常见错误 java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper <de ...
- com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "ExceptionId"
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Exception ...
随机推荐
- springMVC中ajax的使用
springMVC中使用ajax有两种方法,第一种是根据servletAPI来使用ajax,第二种是根据springMVC给我们提供的API来使用. 一.根据servletAPI: springMVC ...
- jquery 上传图片即时预览功能
<script type="text/javascript"> jQuery.fn.extend({ uploadPreview: ...
- suse linux 命令
1.修改vftpd配置文件 vi /etc/vsftpd .conf #listen=YES vi /etc/xinetd.d/vsftpd ...
- 【leetcode】length of last word (easy)
题目: 输入字符串 s,返回其最后一个单词的长度 如 s="Hello World" 返回5 s="Hello World " 返回5 s=&qu ...
- LeetCode 231 Power of Two
Problem: Given an integer, write a function to determine if it is a power of two. Summary: 判断一个数n是不是 ...
- 一个.xib界面文件中设计有多个View
一个新建的.xib文件(Xcode's Interface Builder),有一个默认的View,也就是self.view,是主视图 其他新建的View可以在viewDidLoad()函数中使用 [ ...
- WIN7 64位系统下,右下角的声音和电源图标不见的解决办法
近日,电脑突然出现任务栏右下角的声音和电源图标消失不见的问题,重启仍旧没有修复,后来找到了解决办法 解决办法: 1.Ctrl+Shift+Esc键调出windows资源管理器. 2.找到进程中的exp ...
- stdafx.h的作用
// stdafx.h : include file for standard system include files,// or project specific include files th ...
- java Class<?>和Class<T>等
E - Element (在集合中使用,因为集合中存放的是元素) T - Type(Java 类) K - Key(键) V - Value(值) N - Number(数值类型) ? - 表示不确定 ...
- hdu1722(gcd)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 题意:要使一块蛋糕既能均分给a个人,又能均分给b个人,问至少需要分成几块(不需要每块都一样大小) ...