我需要使用自定义objectWriter,这取决于在webflux应用程序中编写JSON响应的条件。
@Override
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
/*Few writers can be use there depend on some condtions*/
ObjectWriter writer = ObjectWriterProvider.getObjectWriter(/**/);
/*set writer */
return super.handleResult(exchange, result);
}
有
ObjectWriterInjector.set(new Modifier(objectWriter, prettyPrint));
JAX-RS
我有什么方法可以在webflux中使用自定义对象编写器,而不必重写完整的super.handleResult
方法?
答案 0 :(得分:1)
将此bean添加到您的配置类中。您可以自定义ObjectMapper。
@Bean
public Jackson2ObjectMapperBuilder configureObjectMapper() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
ObjectMapper objectMapper = new ObjectMapper();
//objectMapper.writer(Yourwritter);
builder.configure(objectMapper);
return builder;
}