gpt4 book ai didi

json - Jersey Jackson 数据实体在收集时过滤 JsonMappingException

转载 作者:行者123 更新时间:2023-12-04 15:09:26 28 4
gpt4 key购买 nike

我在尝试放置“可选实体过滤”时遇到问题。我有一个抽象类,如下所示:

   // In your Pom
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-entity-filtering</artifactId>
</dependency>
....

//Somewhere in resourceConfig: Register entity-filtering selectable feature.
register(SelectableEntityFilteringFeature.class);
property(SelectableEntityFilteringFeature.QUERY_PARAM_NAME, "select");

register(JacksonFeature.class);

……

在注册“可选实体过滤”之前,一切正常,我对此进行了大量测试。

注册“可选实体过滤”后,出现以下错误:
[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)

这个问题似乎来自
  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;
}

我不明白为什么即使在 POST 请求中也会激活过滤?奇怪的是我没有在请求中放入“select”查询参数!
能否请你帮忙 ?

最佳答案

看来你在使用的时候SelectableEntityFilteringFeature 如果您将 Collection 作为实体放在 Response 中,那么您将得到 JsonMappingException .对我来说这是一个错误。解决方法是您应该将您的收藏封装到 中。通用实体 能够被 Jersey-Jackson 连载。

return Response.status(Status.OK)
.entity(new GenericEntity<Set<MyEntity>>(entityIDs) {}).build();
// Use GenericEntity to avoid JsonMappingException because of the new flow with Filtering

关于json - Jersey Jackson 数据实体在收集时过滤 JsonMappingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35437298/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com