evilfred
evilfred

Reputation: 2416

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

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?

Upvotes: 3

Views: 1393

Answers (1)

Alex
Alex

Reputation: 25613

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

Upvotes: 5

Related Questions