【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 ...
随机推荐
- Slave SQL: Error 'Incorrect string value ... Error_code: 1366
背景: 主从环境一样,字符集是utf8. Slave复制报错,平时复制都正常也没有出现过问题,今天突然报错: :: :: :: :: Error_code: :: perror 1366 MySQL ...
- java入门 第一季3
运算符:算术运算符,赋值运算符,比较运算符,逻辑运算符,条件运算符 1. 算术运算符: 自增和自减只能用于操作变量,不能直接用于操作数值和常量 % 求余数 2. 赋值运算符 = 赋值运算符为变量或常 ...
- .NET微信公众号开发-3.0查询自定义菜单
一.前言 前面我们已经创建好了我们的自定义菜单.那么我们现在要如何查询我们自定义的菜单.原理都是一样的,而且都是相当简单,只是接口地址文档换掉了. 2.0开始编码 同样我们首先创建好我的查询页面,在这 ...
- Httpsqs的安装以及安装过程错误的解决方法 转
需求 :进行商品搜索的时候,要从索引中进行搜索,由于后台要更新商品和插入商品,当时考虑到了怎么来插入新的索引和更新索引的问题,通过讨论,大家决定用Httpsqs这个消息中间来通知插入新索引和删除索引最 ...
- 解决Eclipse里的Maven工程pom.xml文件报:web.xml is missing and <failOnMissingWebXml> is set to true错误
打开eclipse准备进行开发时,发现项目上有个红星号,查看错误后发现报了一个:"web.xml is missing and <failOnMissingWebXml> is ...
- 借教室(codevs 1217)
1217 借教室 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Descrip ...
- chaper3_exercise_Uva1585_score
#include<iostream> #include<string> using namespace std; int main(void) { , j = ; string ...
- 对于类的双重调用的demo
代码如下: package cao.com.duixiang; public class TestCCircle { public static void main(String[] args) { ...
- 创建INnodb的compress表
需要将innodb_file_per_table=1 ,innodb_file_format=Barracuda;; 如: Creating a Compressed Table in a Gener ...
- iOS 判断第一个字符是数字还是汉字
NSString *titleStr = @"琳小兮"; //先截取字符串,拿到第一个字符 NSString *firstStr = [titleStr s ...