FasterXML / jackson-annotations

Core annotations (annotations that only depend on jackson-core) for Jackson data processor
https://github.com/FasterXML/jackson
Apache License 2.0
1.03k stars 330 forks source link

SimpleFilterProvider.addFilter() #29

Closed jml6m closed 10 years ago

jml6m commented 10 years ago

I'm having issues with this method in Jackson 2.3. Here is my piece of code, taken directly from the Wiki docs:

FilterProvider filters = new SimpleFilterProvider().addFilter("test", SimpleBeanPropertyFilter.filterOutAllExcept("name"));

But for some reason, Eclipse (Kepler version) keeps displaying this error: The method addFilter(String, BeanPropertyFilter) in the type SimpleFilterProvider is not applicable for the arguments (String, SimpleBeanPropertyFilter)

It keeps reverting back to the deprecated method even though I'm passing a SimpleBeanPropertyFilter as an argument. I've even looked in SimpleFilterProvider.class and I've found the method I'm trying to use:

/**
* Overloaded variant just to resolve "ties" when using {@link SimpleBeanPropertyFilter}.
*/
public SimpleFilterProvider addFilter(String id, SimpleBeanPropertyFilter filter) {
    _filtersById.put(id, filter);
    return this;
}

Is this a problem with my IDE, or with the library itself?

jml6m commented 10 years ago

Looks like using the FilterExceptFilter class makes the code work:

FilterProvider filters = new SimpleFilterProvider().addFilter("test", FilterExceptFilter.filterOutAllExcept("name"));

Still wondering why this works but the first line doesn't, considering they both return SimpleBeanPropertyFilter

cowtowncoder commented 10 years ago

This is related to refactoring done for 2.3, to allow use of filters for non-POJOs (Maps, mostly). Since Java will use nominal (compile-time) type for method binding in case of overloads it is either IDE problem or incorrect signature of filterOutAllExcept() method. I'll check if latter is the case. But if it is, I'll have to see if it can be fixed: unfortunately such change is not binary compatible.

Or perhaps type of

jml6m commented 10 years ago

Ok, I think the problem originated from me using the 'org.codehaus.jackson' version of the class. It's compiling now that I used the updated package.