gpt4 book ai didi

json - com.fasterxml.jackson.databind.JsonMappingException : Can not resolve PropertyFilter with id 'filterProfile' ; no FilterProvider configured

转载 作者:行者123 更新时间:2023-12-03 21:27:37 26 4
gpt4 key购买 nike

我已经对我的 POJO(profile) 对象进行了动态过滤。过滤逻辑工作正常。需要返回过滤后的对象作为响应。但是在返回配置文件对象时, Jersey 层中面临问题 (MappableException)。

有人可以指导我吗?

过滤逻辑代码:

    ObjectMapper mapper = new ObjectMapper(); 
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
FilterProvider filters = new SimpleFilterProvider() .addFilter("filterProfile",SimpleBeanPropertyFilter.serializeAllExcept(set1))
.addFilter("filterUserDetails", SimpleBeanPropertyFilter.serializeAllExcept(set2)).setFailOnUnknownId(false);

ObjectWriter writer = mapper.writer(filters);
try{
// Printing the filtered json object
filteredJson = writer.writeValueAsString(profile);
}

POJO:

@JsonFilter("filterProfile")
public class Profile {  

@JsonProperty("session")
private Session session;

错误:

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not resolve PropertyFilter with id 'filterProfile'; no FilterProvider configured at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:312) at com.fasterxml.jackson.databind.ser.std.StdSerializer.findPropertyFilter(StdSerializer.java:441) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFieldsFiltered(BeanSerializerBase.java:731) at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:153) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292) at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1429) at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:951) at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:625) 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)

最佳答案

您的代码有意在序列化时过滤属性,因此即使它没有抛出任何异常,过滤器也不会工作,因为它缺少这一行:

mapper.addMixIn(Object.class, Profile.class);

但是,您说“过滤逻辑工作正常”。考虑到这一点,
请发布重现问题的最低限度工作代码(也许是主要方法?)。

关于json - com.fasterxml.jackson.databind.JsonMappingException : Can not resolve PropertyFilter with id 'filterProfile' ; no FilterProvider configured,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46933589/

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