1. 程式人生 > >fasterxml.jackson 將物件轉換為json報錯處理

fasterxml.jackson 將物件轉換為json報錯處理

最近在做查詢的資料遇到如下報錯:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 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.xwj.entity.UserEntity_$$_jvst57f_0["handler"])

仔細看紅色字型部分,發現是實體類中有的欄位值為null,所以在json化的時候,fasterxml.jackson將物件轉換為json報錯

解決辦法:

  在實體類上面加上註解 @JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })