Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring RestTemplate with Jackson throws "Can not resolve BeanPropertyFilter" when using @JsonFilter
    primarykey
    data
    text
    <p>Can I specify the Jackson <code>ObjectMapper</code> that Spring's <code>RestTemplate</code> uses?</p> <p>I'm not 100% that's what I need to do but see below for details.</p> <p><strong>Background:</strong> With help from <a href="https://stackoverflow.com/questions/9314735/how-to-return-a-partial-json-response-using-java">this StackOverflow post</a> I added @JsonFilter to my domain class and edited my jax-rs web service (implemented in CXF). I'm now successfully able to dynamically select which domain class fields to return in my RESTful API. So far so good.</p> <p>I'm using Spring's RestTemplate in my JUnit tests to test my RESTful API. This was working fine until I added @JasonFilter to my domain class. Now I'm getting the following exception:</p> <blockquote> <p>org.springframework.web.client.ResourceAccessException: I/O error: Can not resolve BeanPropertyFilter with id 'apiFilter'; no FilterProvider configured; nested exception is org.codehaus.jackson.map.JsonMappingException: Can not resolve BeanPropertyFilter with id 'apiFilter'; no FilterProvider configured</p> <p>at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)</p> <p>rest of stack trace omitted for brevity</p> <p>Caused by: org.codehaus.jackson.map.JsonMappingException: Can not resolve BeanPropertyFilter with id 'apiFilter'; no FilterProvider configured</p> <p>at org.codehaus.jackson.map.ser.BeanSerializer.findFilter(BeanSerializer.java:252)</p> </blockquote> <p>I was getting a similar problem on the server side and was able to resolve it (with help from <a href="https://stackoverflow.com/questions/9382094/jsonfilter-throws-jsonmappingexception-can-not-resolve-beanpropertyfilter">this post</a>) by giving a <code>FilterProvider</code> to the Jackson <code>ObjectMapper</code> as follows:</p> <pre><code>ObjectMapper mapper = new ObjectMapper(); FilterProvider filters = new SimpleFilterProvider().addFilter("apiFilter", SimpleBeanPropertyFilter.filterOutAllExcept(filterProperties)); </code></pre> <p>Can I do something similar on the RestTemplate side? Any ideas of how to solve this issue are appreciated.</p> <p>Just to be clear, on the client RestTemplate side I do not want to filter the domain object properties at all.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload