`
chembo
  • 浏览: 922654 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

hibernate多对一关系中,JSON serializing对象时报JsonMappingException

阅读更多
我在spinrg mvc中用json返回一个pojo,此pojo与另一个pojo存在多对一关系,这时就会报以下exception:
to use the MappingJacksonJsonView to return one of these objects I receive the following exception:
Org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.HashMap["prospect"]->com.softrek.dms.domain.Prospect["addresses"]->org.hibernate.collection.PersistentSet[0]->com.softrek.dms.domain.Address["prospect"]->com.softrek.dms.domain.Prospect_$$_javassist_1["hibernateLazyInitializer"])
at org.codehaus.jackson.map.ser.StdSerializerProvider$1.serialize(StdSerializerProvider.java:55)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)


这个错其实很易明了,因为你序列化对象A时,需要把里面的多对一关系的B拿出来,而B里面又有A的集合,如此反复,便报这样的错了,解决这个问题的方法在于在 多对一关系中的的一方的set 集体的get 方法前面添加@JsonIgnore即可,如:
@JsonIgnore public Set getStuedntses() {
		return studentses;
	}

添加这个注解后,无论你是lazy="true" or lazy="false"他都不会去序列化你的了!
分享到:
评论

相关推荐

    可以在QT4中使用的JSON库

    QT4 JSON The **qt-json** project is a simple collection of functions for parsing and serializing [JSON][js] data to and from [QVariant][var] hierarchies.

    json序列化jar包

    Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON. What's different about Flexjson is it's control over what gets serialized allowing both deep and ...

    6.Json与Protocolbuf相互转换1

    Json与Protocolbuf相互转换Example serializing to JSON string from Messagestd::string j

    Java XML and JSON: Document Processing for Java SE, 2nd Edition

    Java XML and JSON: ...Master the JSON format for serializing and transmitting data Code against third-party APIs such as Jackson, mJson, Gson, JsonPath Master Oracle’s JSON-P API in a Java SE context

    Java 问题和分析 Serializing a primitive with ObjectOutStream

    需要对一个长整型(long)的原始值进行序列化

    FlexJson1.7 Jar包

    Flexjson is a lightweight library for serializing Java objects into JSON. FlexJson,一个轻量级的Jar库,可以将Java对象序列化成Json格式

    Serializing Interfaces in SAP AIF.zip

    sap press doc 解压密码:abap_developer

    toml++tomlplusplus-master TOML配置文件C++库

    Supports serializing to JSON and YAML Proper UTF-8 handling (incl. BOM) C++17 (plus some C++20 features where available, e.g. experimental support for char8_t strings) Doesn't require RTTI Works with ...

    PHP高级OOP技术演示

    序列化(Serializing) PHP不支持永久对象,在OOP中永久对象是可以在多个应用的引用中保持状态和功能的对象,这意味着拥有将对象保存到一个文件或数据库中的能力,而 且可以在以后装入对象。这就是所谓的序列化机制。...

    python模块

    (pickle的过程也被称serializing,marshalling或者flattening,pickle同时可以用来将bytes流反序列化为python的对象)。 * sys:sys模块包含了跟python解析器和环境相关的变量和函数。 * 其他: atexit,gc,inspect...

    ZendFramework中文文档

    3.2.2. 高级使用:持久一个 DbTable 结果对象 3.2.3. 高级用法示例 3.3. 摘要式认证 3.3.1. 简介 3.3.2. 规范(Specifics) 3.3.3. 身份(Identity) 3.4. HTTP 认证适配器 3.4.1. 简介 3.4.2. 设计回顾 ...

    Feedpipes:开源.NET库,用于解析和序列化RSS,Atom和JSON feed

    开源.NET库,用于解析和序列化RSS,Atom和JSON feed。 重要:该库当前仅处于预发行版本中。 该库是用C#编写的,并带有,因此可以随意进行分叉或在商业上使用。 感谢您提供任何反馈,请访问页面或给我发送。 ...

    Android代码-LoganSquare

    The fastest JSON parsing and serializing library available for Android. Based on Jackson's streaming API, LoganSquare is able to consistently outperform GSON and Jackson's Databind library by 400% or ...

    Serialize.Linq:C#库用于序列化LINQ表达式

    它支持(但不限于)的格式为JSON,XML和BINARY。 安装 通过简单安装: PM> Install-Package Serialize.Linq 建立源 git clone https://github.com/esskar/Serialize.Linq.git 例子 包含一个有效的WCF和REST API...

    Python常用模块介绍

    * copy: copy模块提供了对复合(compound)对象(list,tuple,dict,custom class)进行浅拷贝和深拷贝的功能。 * pickle: pickle模块被用来序列化python的对象到bytes流,从而适合存储到文件,网络传输,或...

    pata_cs5535.rar_If...

    Review errata to see if serializing is necessary.

    yaserde:另一个 SerializerDeserializer

    skip_serializing_if :如果条件为真,则跳过此字段的序列化 text : 此字段与文本内容匹配 自定义解串器 任何类型都可以定义自定义反序列化器和/或序列化器。 要实现它,定义 YaDeserialize/YaSerialize 的实现 ...

    Practical Hadoop Ecosystem

    学习大数据的最大问题是,东西太多,而且不断会有新东西出来。就我个人来说,本书的最大优点是,帮你把Hadoop生态系统内最典型的一些框架和工具进行分类,让你明白它们各自是做什么的,处于体系内的哪个Level。 ...

    mybatis-3.4.6.zip

    Serializing and deserializing cached objects causes NullPointerException. #1084 Invalid error message 'Two methods with same method signature but not providing classes assignable?' in System.err. #...

    Atom-atom,用于序列化Atom Web内容联合格式的库https://crates.io/crates/atom联合.zip

    Atom-atom.zip,Library for serializing the Atom web content syndication format https://crates.io/crates/atom_syndication原子,atom是一个用web技术构建的开源文本编辑器。

Global site tag (gtag.js) - Google Analytics