package com.fasterxml.jackson.databind.filter;

import java.util.HashMap;
import java.util.Map;


import com.fasterxml.jackson.annotation.*;

import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

/**
 * Unit tests for ensuring that entries accessible via "any filter"
 * can also be filtered with JSON Filter functionality.
 */
public class TestAnyGetterFiltering extends BaseMapTest
{
    @JsonFilter("anyFilter")
    public static class AnyBean
    {
        private Map<String, String> properties = new HashMap<String, String>();
        {
            properties.put("a", "1");
            properties.put("b", "2");
        }

        @JsonAnyGetter
        public Map<String, String> anyProperties()
        {
            return properties;
        }
    }

    /*
    /**********************************************************
    /* Unit tests
    /**********************************************************
     */
    
    // should also work for @JsonAnyGetter, as per [JACKSON-516]
    public void testAnyGetterFiltering() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        FilterProvider prov = new SimpleFilterProvider().addFilter("anyFilter",
                SimpleBeanPropertyFilter.filterOutAllExcept("b"));
        assertEquals("{\"b\":\"2\"}", mapper.writer(prov).writeValueAsString(new AnyBean()));
    }
}

@@ -62,39 +62,10 @@
 til.
-HashMap;%0Aimport java.util.Map;%0A
+*;
 %0A%0Aim
@@ -972,24 +972,473 @@
    %7D%0A    %7D%0A%0A
+    public static class AnyBeanWithIgnores%0A    %7B%0A        private Map%3CString, String%3E properties = new LinkedHashMap%3CString, String%3E();%0A        %7B%0A            properties.put(%22a%22, %221%22);%0A            properties.put(%22bogus%22, %222%22);%0A            properties.put(%22b%22, %223%22);%0A        %7D%0A%0A        @JsonAnyGetter%0A        @JsonIgnoreProperties(%7B %22bogus%22 %7D)%0A        public Map%3CString, String%3E anyProperties()%0A        %7B%0A            return properties;%0A        %7D%0A    %7D%0A%0A
     /*%0A    /
@@ -1503,25 +1503,27 @@
 %0A    /* 
-Unit test
+Test method
 s%0A    /*
@@ -1592,78 +1592,9 @@
  */%0A
-    %0A    // should also work for @JsonAnyGetter, as per %5BJACKSON-516%5D
 %0A
+
     
@@ -1846,24 +1846,24 @@
 cept(%22b%22));%0A
-
         asse
@@ -1949,11 +1949,282 @@
 );%0A    %7D
+%0A%0A    // for %5Bdatabind#1142%5D%0A    public void testAnyGetterIgnore() throws Exception%0A    %7B%0A        ObjectMapper mapper = new ObjectMapper();%0A        assertEquals(aposToQuotes(%22%7B'a':'1','b':'3'%7D%22),%0A                mapper.writeValueAsString(new AnyBeanWithIgnores()));%0A    %7D
 %0A%7D%0A

Add a test to show #1142 was already working