项目中,父层是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异常处理的更多相关文章

  1. SpringBoot JPA懒加载异常 - com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy

    问题与分析 某日忽然发现在用postman测试数据时报错如下: com.fasterxml.jackson.databind.JsonMappingException: could not initi ...

  2. 400 bad Request: JackSon将json串转成List<Object>,异常com.fasterxml.jackson.databind.JsonMappingException

    最近遇到的400, 以前总以为 400 就是参数不匹配造成的,直到今天遇到这个问题 控制台报错如下:  com.fasterxml.jackson.databind.JsonMappingExcept ...

  3. com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input

    作者原创,转载请注明转载地址 第一次遇到该异常,在网上搜了很长时间也没找到解决答案,特此记录 1.异常展示: com.fasterxml.jackson.databind.JsonMappingExc ...

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

  5. com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field 异常

    分享牛原创(尊重原创 转载对的时候第一行请注明,转载出处来自分享牛http://blog.csdn.net/qq_30739519) 1.1.1. 前言 近期在使用ObjectMapper对象将jso ...

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

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

  8. java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper

    RabbitMq配置时常见错误 java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper <de ...

  9. com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "ExceptionId"

    com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Exception ...

随机推荐

  1. ACM/ICPC 之 BFS-广搜进阶-八数码(经典)(POJ1077+HDU1043)

    八数码问题也称为九宫问题.(本想查查历史,结果发现居然没有词条= =,所谓的历史也就不了了之了) 在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的某一数字,不同棋子上标的数字不相同.棋盘上还有一个 ...

  2. ffmpeg-20160510-git-bin

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...

  3. K3问题 无法创建中间层 组件<KdSvrMgr>无法正常工作

    K3遇到如下问题 一直无法解决,这个是本地计算机的问题,跟服务器没关系,采用笨方法,重装K3(重装到本磁盘.其他磁盘),重装系统,虽然笨,但最后都解决掉了

  4. NEFU 504 new Flip Game (高斯消元)

    题目链接 题解:和 poj1753Filp game 差不多,区别在于t组数据并且翻转的时候多了一个左上角. #include <iostream> #include <cstdio ...

  5. ios企业应用发布流程

    转载自:http://blog.csdn.net/justinjing0612/article/details/8758692留作备忘 企业发布app的 过程比app store 发布的简单多了,没那 ...

  6. MVC3.0删除数据的时候给提示信息

    Index.cshtml代码: @model IEnumerable<FirstMvc.Models.Book> <script type="text/javascript ...

  7. iOS进阶面试题----Block部分

    1 什么是block 对于闭包 (block),有很多定义,其中闭包就是能够读取其它函数内部变量的函数,这个定义即接近本质又较好理解.对于刚接触Block的同学,会觉得有些绕, 因为我们习惯写这样的程 ...

  8. js中我的注释规范

    模块功能描述说明: /** * ------------------------------------------------------------------ * 模块描述说明 * ------ ...

  9. C/C++中调用python文件

    1.将python27安装目录下include.libs文件夹拷贝至Demo程序目录. 2.Demo项目设置包含Python.h.python27.lib); (因为安装python27的时候,pyt ...

  10. iOS 文件大小转换成 KB、MB、GB 。。。

    -(NSString *) convertFileSize:(long long)size { ; ; ; if (size >= gb) { return [NSString stringWi ...