Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6872149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:53:29+00:00 2026-05-27T03:53:29+00:00

Is there a way to register a global property filter in ObjectMapper? Global means

  • 0

Is there a way to register a global property filter in ObjectMapper?
Global means that it will be applied to all serialized beans. I can’t use annotations (I can’t modify serialized beans) and don’t know what properties the beans have.
The filtering should be name based.

My first idea was to write a custom serializer, but I don’t know what should I pass to the constructor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:53:30+00:00Added an answer on May 27, 2026 at 3:53 am

    I’d make use of a FilterProvider. It’s a little involved, but not too unwieldy.

    import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
    import org.codehaus.jackson.annotate.JsonMethod;
    import org.codehaus.jackson.map.ObjectMapper;
    import org.codehaus.jackson.map.ObjectWriter;
    import org.codehaus.jackson.map.annotate.JsonFilter;
    import org.codehaus.jackson.map.ser.FilterProvider;
    import org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter;
    import org.codehaus.jackson.map.ser.impl.SimpleFilterProvider;
    
    public class JacksonFoo
    {
      public static void main(String[] args) throws Exception
      {
        Bar bar = new Bar();
        bar.id = "42";
        bar.name = "James";
        bar.color = "blue";
        bar.foo = new Foo();
        bar.foo.id = "7";
        bar.foo.size = "big";
        bar.foo.height = "tall";
    
        ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY);
        System.out.println(mapper.writeValueAsString(bar));
        // output: 
        // {"id":"42","name":"James","color":"blue","foo":{"id":"7","size":"big","height":"tall"}}
    
        String[] ignorableFieldNames = { "id", "color" };
    
        FilterProvider filters = new SimpleFilterProvider().addFilter("filter properties by name", SimpleBeanPropertyFilter.serializeAllExcept(ignorableFieldNames));
    
        mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY);
        mapper.getSerializationConfig().addMixInAnnotations(Object.class, PropertyFilterMixIn.class);
        ObjectWriter writer = mapper.writer(filters);
    
        System.out.println(writer.writeValueAsString(bar));
        // output:
        // {"name":"James","foo":{"size":"big","height":"tall"}}
      }
    }
    
    @JsonFilter("filter properties by name")
    class PropertyFilterMixIn
    {
    
    }
    
    class Bar
    {
      String id;
      String name;
      String color;
      Foo foo;
    }
    
    class Foo
    {
      String id;
      String size;
      String height;
    }
    

    For other approaches and more information, I recommend the following resources.

    • http://wiki.fasterxml.com/JacksonJsonViews
    • http://www.cowtowncoder.com/blog/archives/2011/02/entry_443.html
    • http://wiki.fasterxml.com/JacksonFeatureJsonFilter
    • http://www.cowtowncoder.com/blog/archives/2011/09/entry_461.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to register for global mouse moved events in Cocoa? I
Is there a way to register a method so that it's automatically called as
Is there a way to register for events or receive any other kinds of
Is there a way for a custom panel for Flash CS4 to register for
Is there any function / global variable in PHP that returns the current state
Is there any way to register event listeners for components at a central point
Is there way to get file from windows xp command prompt? I tried to
Is there way to automatically maximize the output window on hitting build and then
Is there way to copy a file into Plone with WebDAV and have Plone
is there way how to get name ov event from Lambda expression like with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.