Jersey jackson禁用filterprovider(Jersey jackson disable filterprovider)
最近我开始使用SecurityEntityFilteringFeature。 在泽西环境中放置在代码下方。
environment.jersey().register(SecurityEntityFilteringFeature.class); environment.jersey().register(JacksonFeature.class);
我返回自定义对象或地图的所有资源类都开始抛出异常
com.fasterxml.jackson.databind.JsonMappingException: Can not resolve PropertyFilter with id 'uk.co.froot.demo.openid.resources.PublicOAuthResource$1'; no FilterProvider configured at com.fasterxml.jackson.databind.ser.std.StdSerializer.findPropertyFilter(StdSerializer.java:285) at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:459) at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:29) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:129) at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:851) at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:648) at org.glassfish.jersey.jackson.internal.FilteringJacksonJaxbJsonProvider.writeTo(FilteringJacksonJaxbJsonProvider.java:135) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1128) at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:664) at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:421) at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:411)
Recently I started using SecurityEntityFilteringFeature. Placed below code in jersey environment.
environment.jersey().register(SecurityEntityFilteringFeature.class); environment.jersey().register(JacksonFeature.class);
All my resource classes which are returning custom object or map, started throwing below exception
com.fasterxml.jackson.databind.JsonMappingException: Can not resolve PropertyFilter with id 'uk.co.froot.demo.openid.resources.PublicOAuthResource$1'; no FilterProvider configured at com.fasterxml.jackson.databind.ser.std.StdSerializer.findPropertyFilter(StdSerializer.java:285) at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:459) at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:29) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:129) at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:851) at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:648) at org.glassfish.jersey.jackson.internal.FilteringJacksonJaxbJsonProvider.writeTo(FilteringJacksonJaxbJsonProvider.java:135) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1128) at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:664) at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:421) at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:411)
原文:https://stackoverflow.com/questions/31079510
更新时间:2023-09-07 08:09