Jackson is throwing a weird exception that I don't know how to fix. I'm using Spring, Hibernate and Jackson.

I have already considered that lazy-loading is causing the problem, but I have taken measures to tell Jackson to NOT process various properties as follows:

@JsonIgnoreProperties({ "sentMessages", "receivedMessages", "educationFacility" })
public class Director extends UserAccount implements EducationFacilityUser {
   ....
}

我对所有其他UserAccount子类也做了同样的事情.

Here's the exception being thrown:

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.ArrayList[46]->jobprep.domain.educationfacility.Director_$$_javassist_2["handler"])
    at org.codehaus.jackson.map.ser.StdSerializerProvider$1.serialize(StdSerializerProvider.java:62)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:268)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:146)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:118)
    at org.codehaus.jackson.map.ser.ContainerSerializers$IndexedListSerializer.serializeContents(ContainerSerializers.java:236)
    at org.codehaus.jackson.map.ser.ContainerSerializers$IndexedListSerializer.serializeContents(ContainerSerializers.java:189)
    at org.codehaus.jackson.map.ser.ContainerSerializers$AsArraySerializer.serialize(ContainerSerializers.java:111)
    at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:296)
    at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:224)
    at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:925)
    at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:153)

建议我如何才能获得更多信息,以了解是什么导致了这一点?有人知道怎么修吗?

EDIT: I discovered that getHander() and other get*() methods exist on the proxy object. GRR!! Is there any way I can tell Jackson to not process anything on the proxy, or am I sol? This is really weird because the method that spits out the JSON only crashes under certain circumstances, not all the time. Nonetheless, it's due to the get*() methods on the proxy object.

旁白:代理人是邪恶的.它们扰乱了Jackson、equals()和常规Java编程的许多其他部分.我很想彻底抛弃冬眠:/

推荐答案

It's not ideal, but you could disable Jackson's auto-discovery of JSON properties, using @JsonAutoDetect at the class level. This would prevent it from trying to handle the Javassist stuff (and failing).

This means that you then have to annotate each getter manually (with @JsonProperty), but that's not necessarily a bad thing, since it keeps things explicit.

Json相关问答推荐

两种情况下过滤的JOLT规范

PowerShell脚本-替换json数组(转义$var将被视为不带双引号的文本)

Flutter -控制器问题-JSON API

使用jq过滤复杂json对象中的数据

规范化JSON数据

使用 Power BI 中的 Deneb 视觉效果绘制面积图中的 X 轴日期

JOLT转换并向输出添加新数组

将JSON行转换为TSV格式, for each 数组项生成单独的行

在这种情况下我如何实现 UnmarshalJSON 并且只为一个接口字段定义特殊行为?

将具有多个级别的 json 读入 DataFrame [python]

如何在 Flutter 中遍历嵌套的动态 JSON 文件

Oracle Apex - 将 JSON 对象分配给变量以返回

在 json 嵌入的 YAML 文件中 - 使用 Python 仅替换 json 值

如何为所有 API 端点全局设置 http.ResponseWriter Content-Type 标头?

Swift:如何从字典中删除空值?

了解 JSON Schema 草稿版本 4 中的additionalProperties关键字

在 Postgres 中向 JSON 对象添加元素

没有默认构造函数的杰克逊第 3 方类

jQuery JSON 响应总是触发 ParseError

python追加到json对象中的数组