Examples of FilterProvider


Examples of com.fasterxml.jackson.databind.ser.FilterProvider

    public void testMapFilteringViaClass() throws Exception
    {
        FilteredBean bean = new FilteredBean();
        bean.put("a", 4);
        bean.put("b", 3);
        FilterProvider prov = new SimpleFilterProvider().addFilter("filterForMaps",
                SimpleBeanPropertyFilter.filterOutAllExcept("b"));
        String json = MAPPER.writer(prov).writeValueAsString(bean);
        assertEquals(aposToQuotes("{'b':3}"), json);
    }
View Full Code Here

Examples of com.fasterxml.jackson.databind.ser.FilterProvider

    }
   
    // [Issue#522]
    public void testMapFilteringWithAnnotations() throws Exception
    {
        FilterProvider prov = new SimpleFilterProvider().addFilter("filterX",
                new MyMapFilter());
        String json = MAPPER.writer(prov).writeValueAsString(new MapBean());
        // a=1 should become a=2
        assertEquals(aposToQuotes("{'values':{'a':2}}"), json);
    }
View Full Code Here

Examples of com.fasterxml.jackson.databind.ser.FilterProvider

     */
    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;
    }
View Full Code Here

Examples of com.fasterxml.jackson.databind.ser.FilterProvider

    private final ObjectMapper MAPPER = mapperWithModule();
   
    public void testSimpleInclusionFilter() throws Exception
    {
        FilterProvider prov = new SimpleFilterProvider().addFilter("RootFilter",
                SimpleBeanPropertyFilter.filterOutAllExcept("a"));
        assertEquals("{\"a\":\"a\"}", MAPPER.writer(prov).writeValueAsString(new Bean()));

        // [JACKSON-504]: also verify it works via mapper
        ObjectMapper mapper = new ObjectMapper();
View Full Code Here

Examples of com.fasterxml.jackson.databind.ser.FilterProvider

        assertEquals("{\"a\":\"a\"}", mapper.writeValueAsString(new Bean()));
    }

    public void testSimpleExclusionFilter() throws Exception
    {
        FilterProvider prov = new SimpleFilterProvider().addFilter("RootFilter",
                SimpleBeanPropertyFilter.serializeAllExcept("a"));
        assertEquals("{\"b\":\"b\"}", MAPPER.writer(prov).writeValueAsString(new Bean()));
    }
View Full Code Here

Examples of com.fasterxml.jackson.databind.ser.FilterProvider

    }
   
    // defaulting, as per [JACKSON-449]
    public void testDefaultFilter() throws Exception
    {
        FilterProvider prov = new SimpleFilterProvider().setDefaultFilter(SimpleBeanPropertyFilter.filterOutAllExcept("b"));
        assertEquals("{\"b\":\"b\"}", MAPPER.writer(prov).writeValueAsString(new Bean()));
    }
View Full Code Here

Examples of com.fasterxml.jackson.databind.ser.FilterProvider

    }

    // Wrt [Issue#306]
    public void testFilterOnProperty() throws Exception
    {
        FilterProvider prov = new SimpleFilterProvider()
            .addFilter("RootFilter", SimpleBeanPropertyFilter.filterOutAllExcept("a"))
            .addFilter("b", SimpleBeanPropertyFilter.filterOutAllExcept("b"));

        assertEquals("{\"first\":{\"a\":\"a\"},\"second\":{\"b\":\"b\"}}",
                MAPPER.writer(prov).writeValueAsString(new FilteredProps()));
View Full Code Here

Examples of com.fasterxml.jackson.databind.ser.FilterProvider

        return res;
   

    private <T> String filter(Object src, Class<T> filterClass,
            FilterContext fc,  Boolean clean, String... filterAttr) throws Exception {
        FilterProvider filter = null;
        if (src != null) {
            filter = checkFilter(fc, src.getClass(), filterClass,
                filterAttr);
        }
        getLogger().info("filtering with filter "+ filter);
View Full Code Here

Examples of com.fasterxml.jackson.databind.ser.FilterProvider

        mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
        mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);
       
        mapper.addMixInAnnotations(Object.class, IgnoreTypeMixIn.class);
       
        final FilterProvider filters = new SimpleFilterProvider().addFilter("storedDataFilter", SimpleBeanPropertyFilter.serializeAllExcept("storedData"));

        final ObjectWriter ssWriter = mapper.writer(filters);
        final ObjectReader ssReader = mapper.reader(sus.getClass());
       
        final String susString = ssWriter.writeValueAsString(sus);
View Full Code Here

Examples of com.fasterxml.jackson.databind.ser.FilterProvider

    public void testMixinNoCopy() throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        mapper.findAndRegisterModules();
       
        mapper.addMixInAnnotations(Object.class, PortletRenderExecutionEventFilterMixIn.class);
        final FilterProvider filterProvider = new SimpleFilterProvider().addFilter(PortletRenderExecutionEventFilterMixIn.FILTER_NAME, SimpleBeanPropertyFilter.filterOutAllExcept("fname", "executionTimeNano", "parameters"));
        final ObjectWriter portletEventWriter = mapper.writer(filterProvider);
       
        final String result = portletEventWriter.writeValueAsString(createEvent());
       
        assertEquals("{\"@c\":\".PortletRenderExecutionEvent\",\"fname\":\"fname1\",\"executionTimeNano\":123450000,\"parameters\":{}}", result);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.