Jackson JSON Processor
  1. Jackson JSON Processor
  2. JACKSON-825

Problems using FilterProvider with Jackson 2.0

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: 2.0.0
    • Fix Version/s: None
    • Component/s: Serializer
    • Labels:
      None
    • Number of attachments :
      0

      Description

      I followed the wiki example using Jackson 2.0 and wrote the following code:

      ObjectMapper mapper = new ObjectMapper();
      
      // first, construct filter provider to exclude all properties but 'name', bind it as 'myFilter'
      FilterProvider filters = new SimpleFilterProvider().addFilter("myFilter",
      SimpleBeanPropertyFilter.filterOutAllExcept("name"));
      
      // and then serialize using that filter provider:
      String json = mapper.writer(filters).writeValueAsString(new Object() {
        public String name = "a";
        public int num = 2;
      });
      
      System.out.println(json);
      

      I had to change "filterWriter(filters)" to "writer(filters)" due to API change from Jackson 1.* to 2.0.
      The output of this code is:

      {"name":"a","num":2}

      I expected to get:

      {"name":"a"}

      without the "num" property.
      It works as expected in Jackson 1.7.4.

        Activity

        Tatu Saloranta made changes -
        Field Original Value New Value
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Not A Bug [ 6 ]

          People

          • Assignee:
            Tatu Saloranta
            Reporter:
            Nir Shemy
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: