这两天在处理neo4j取出来的数据的时候遇到了一个报错,查了下,具体是因为null实体造成的
错误
org.springframework.http.converter.HttpMessageConversionException:
Type definition error: [simple type, class
org.neo4j.driver.internal.InternalPath S e l f C o n t a i n e d S e g m e n t ] ; n e s t e d e x c e p t i o n i s c o m . f a s t e r x m l . j a c k s o n . d a t a b i n d . e x c . I n v a l i d D e f i n i t i o n E x c e p t i o n : N o s e r i a l i z e r f o u n d f o r c l a s s o r g . n e o 4 j . d r i v e r . i n t e r n a l . I n t e r n a l P a t h SelfContainedSegment]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.neo4j.driver.internal.InternalPath SelfContainedSegment];nestedexceptioniscom.fasterxml.jackson.databind.exc.InvalidDefinitionException:Noserializerfoundforclassorg.neo4j.driver.internal.InternalPathSelfContainedSegment and no
properties discovered to create BeanSerializer (to avoid exception,
disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference
chain:
java.util.ArrayList[1]->java.util.HashMap[“path”]->org.neo4j.driver.internal.InternalPath$SelfContainedSegment[0])
解决方式
重写ObjectMapper,加入disable SerializationFeature.FAIL_ON_EMPTY_BEANS
@Bean
public ObjectMapper objectMapper(){
return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}