杰克逊提供的方法:
ObjectWriter ObjectMapper.writer(FilterProvider)
ObjectWriter ObjectMapper.writer(PrettyPrinter)
ObjectWriter ObjectMapper.writerWithDefaultPrettyPrinter()
但是我想在我的作家中使用漂亮的打印和自定义的FilterProvider。如何让作家同时使用两者?
答案 0 :(得分:4)
您可以在任何ObjectWriter
方法返回的ObjectMapper.write()
实例上进行配置:
ObjectWriter objectWriter = ObjectMapper.writer(yourFilterProvider).withPrettyPrinter(yourPrettyPrinter);
// or
ObjectWriter objectWriter = ObjectMapper.writer(yourPrettyPrinter).withFilters(yourPrettyPrinter);
有关详细信息,请参阅ObjectWriter class