Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Co

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: 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); nested exception is 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.Controller.User_$$_jvstdcc_0["handler"])


在spring boot框架中出通过id查询数据的时候出现的这个问题,

是因为查询的数据返回时空出现的异常:

使用来个一个注解,添加在实体类上就可以解决了

@JsonIgnoreProperties({ "handler","hibernateLazyInitializer" })

这个注解的含义:

在此标记不生成json对象的属性

因为jsonplugin用的是java的内审机制.hibernate会给被管理的pojo加入一个hibernateLazyInitializer属性,jsonplugin会把hibernateLazyInitializer也拿出来操作,并读取里面一个不能被反射操作的属性就产生了这个异常.  

 

不过我用的是jackson来转json,所以想到了用annotation来排除hibernateLazyInitializer 这个属性

在你的pojo类声明加上:

  1. @JsonIgnoreProperties(value={"hibernateLazyInitializer"})    
@JsonIgnoreProperties就是标注 哪个属性 不用转化为json的
org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public com.xymzsfxy.backend.returncode.Result com.xymzsfxy.backend.controller.admin.ProductController.update(com.xymzsfxy.backend.entity.Product) with 2 errors: [Field error in object ‘product’ on field ‘createdTime’: rejected value [2025-03-06T15:23:49.000Z]; codes [typeMismatch.product.createdTime,typeMismatch.createdTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [product.createdTime,createdTime]; arguments []; default message [createdTime]]; default message [Failed to convert property value of type ‘java.lang.String’ to required type ‘java.util.Date’ for property ‘createdTime’; Failed to convert from type [java.lang.String] to type [@javax.persistence.Column @com.fasterxml.jackson.annotation.JsonFormat java.util.Date] for value [2025-03-06T15:23:49.000Z]]] [Field error in object ‘product’ on field ‘updatedTime’: rejected value [2025-03-06T15:23:49.000Z]; codes [typeMismatch.product.updatedTime,typeMismatch.updatedTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [product.updatedTime,updatedTime]; arguments []; default message [updatedTime]]; default message [Failed to convert property value of type ‘java.lang.String’ to required type ‘java.util.Date’ for property ‘updatedTime’; Failed to convert from type [java.lang.String] to type [@javax.persistence.Column @com.fasterxml.jackson.annotation.JsonFormat java.util.Date] for value [2025-03-06T15:23:49.000Z]]] at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:177)还是这个问题
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值