How do I make an ObjectWriter that uses both filters and pretty print?

jackson, java, json

Solution

You can take still configure this on the `ObjectWriter` instance returned by any of the `ObjectMapper.write()` method:

ObjectWriter objectWriter = ObjectMapper.writer(yourFilterProvider).withPrettyPrinter(yourPrettyPrinter); 
// or
ObjectWriter objectWriter = ObjectMapper.writer(yourPrettyPrinter).withFilters(yourPrettyPrinter); 

See the ObjectWriter class for more information

Problem

Jackson offers the methods: ``` ObjectWriter ObjectMapper.writer(FilterProvider) ObjectWriter ObjectMapper.writer(PrettyPrinter) ObjectWriter ObjectMapper.writerWithDefaultPrettyPrinter() ``` But I want to use both pretty printing and a custom FilterProvider in my writer. How do I get a writer that uses both?

Original source