jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
Jackson JSON Processor
  • Jackson JSON Processor
  • JACKSON-724

Simpler Property Filtering

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Cannot Reproduce
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: Serializer
  • Labels:
    None
  • Number of attachments :
    0

Description

For serialization, a simpler property filtering configuration should be available to not require use of annotations.

A good solution might be to allow registering type-based filters with a SimpleFilterProvider, such that this code

public class JacksonFoo
{
  public static void main(String[] args) throws Exception
  {
    ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY);
    mapper.getSerializationConfig().addMixInAnnotations(Object.class, PropertyFilterMixIn.class);

    String[] ignorableFieldNames = { "id", "color" };
    FilterProvider filters = new SimpleFilterProvider().addFilter("filter properties by name", SimpleBeanPropertyFilter.serializeAllExcept(ignorableFieldNames));
    ObjectWriter writer = mapper.writer(filters);

    System.out.println(writer.writeValueAsString(new Bar()));
    // output:
    // {"name":"James","foo":{"size":"big","height":"tall"}}
  }
}

@JsonFilter("filter properties by name")
class PropertyFilterMixIn
{
  
}

class Bar
{
  String id = "42";
  String name = "Fred";
  String color = "blue";
  Foo foo = new Foo();
}

class Foo
{
  String id = "99";
  String size = "big";
  String height = "tall";
}

...might then be reduced to just

public class JacksonFoo
{
  public static void main(String[] args) throws Exception
  {
    ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY);

    String[] ignorableFieldNames = { "id", "color" };
    FilterProvider filters = new SimpleFilterProvider().addFilter(Bar.class, SimpleBeanPropertyFilter.serializeAllExcept(ignorableFieldNames));
    ObjectWriter writer = mapper.writer(filters);

    System.out.println(writer.writeValueAsString(new Bar()));
    // output:
    // {"name":"James","foo":{"size":"big","height":"tall"}}
  }
}

class Bar
{
  String id = "42";
  String name = "Fred";
  String color = "blue";
  Foo foo = new Foo();
}

class Foo
{
  String id = "99";
  String size = "big";
  String height = "tall";
}

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Programmer Bruce added a comment - 24/Nov/11 11:50 AM

...or if

addFilter(Bar.class ...

is too dissimilar to the current configuration approach, then

addFilter(Object.class ...

would be more appropriate in the example above.

Show
Programmer Bruce added a comment - 24/Nov/11 11:50 AM ...or if addFilter(Bar.class ... is too dissimilar to the current configuration approach, then addFilter( Object .class ... would be more appropriate in the example above.
Hide
Permalink
Tatu Saloranta added a comment - 24/Nov/11 11:57 AM

Ok, I have to think about this a bit. Obviously if this could be implemented using existing facilities, it'd be great (make use of default filter etc perhaps?).
And as usual, contributions welcome.

Also, since we are heading for 2.0, which is a backwards incompatible update, we have more freedom in changing API of existing pieces as well if absolutely necessary.

Show
Tatu Saloranta added a comment - 24/Nov/11 11:57 AM Ok, I have to think about this a bit. Obviously if this could be implemented using existing facilities, it'd be great (make use of default filter etc perhaps?). And as usual, contributions welcome. Also, since we are heading for 2.0, which is a backwards incompatible update, we have more freedom in changing API of existing pieces as well if absolutely necessary.
Hide
Permalink
Tatu Saloranta added a comment - 05/Feb/13 11:27 AM

Will close as part of Codehaus Jackson Jira deprecation: new concrete RFEs can be filed at:

https://github.com/FasterXML/jackson-databind/issues

Show
Tatu Saloranta added a comment - 05/Feb/13 11:27 AM Will close as part of Codehaus Jackson Jira deprecation: new concrete RFEs can be filed at: https://github.com/FasterXML/jackson-databind/issues

People

  • Assignee:
    Tatu Saloranta
    Reporter:
    Programmer Bruce
Vote (1)
Watch (2)

Dates

  • Created:
    24/Nov/11 11:47 AM
    Updated:
    05/Feb/13 11:27 AM
    Resolved:
    05/Feb/13 11:27 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.