jersey 过滤_Jersey Jackson数据实体在集合上过滤JsonMappingException

I have an issue when trying to put in place the “selectable entity filtering”. I have an Abstract class like following one:

// In your Pom

org.glassfish.jersey.ext

jersey-entity-filtering

....

//Somewhere in resourceConfig: Register entity-filtering selectable feature.

register(SelectableEntityFilteringFeature.class);

property(SelectableEntityFilteringFeature.QUERY_PARAM_NAME, "select");

register(JacksonFeature.class);

…..

Before registering the “selectable entity filtering” all was working fine, I tested that a lot.

And after registering “selectable entity filtering” I have the following error:

[2016-02-15 17:25:36] - DEBUG EntityMapper:116 [http-bio-8080-exec-3] Preparing query INSERT INTO

[2016-02-15 17:25:43] - ERROR JsonMappingExceptionMapper:29 [http-bio-8080-exec-3] Malformed Json!

com.fasterxml.jackson.databind.JsonMappingException: Can not resolve PropertyFilter with id 'java.util.HashMap'; no FilterProvider configured

at com.fasterxml.jackson.databind.ser.std.StdSerializer.findPropertyFilter(StdSerial izer.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:650)

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)

It seems that the issue comes from the

StdSerializer.findPropertyFilter(StdSerializer.java:285)

protected PropertyFilter findPropertyFilter(SerializerProvider provider,

Object filterId, Object valueToFilter)

throws JsonMappingException

{

FilterProvider filters = provider.getFilterProvider();

// Not ok to miss the provider, if a filter is declared to be needed.

if (filters == null) {

throw new JsonMappingException("Can not resolve PropertyFilter with id '"+filterId+"'; no FilterProvider configured");

}

PropertyFilter filter = filters.findPropertyFilter(filterId, valueToFilter);

// But whether unknown ids are ok just depends on filter provider; if we get null that's fine

return filter;

}

I don’t understand why the filtering is activated even in POST requests ? The strange thing is I didn’t put the “select” query parameter in the request!

Could you please help ?

解决方案

It seems that when you are using the SelectableEntityFilteringFeature and if you are putting Collection as an Entity in Response then you will get a JsonMappingException. For me it is a bug. The work around is you should encapsulate your collection into GenericEntity to be able to be serialized by Jersey-Jackson.

return Response.status(Status.OK)

.entity(new GenericEntity>(entityIDs) {}).build();

// Use GenericEntity to avoid JsonMappingException because of the new flow with Filtering

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值