【发布时间】:2020-05-27 17:50:03
【问题描述】:
我不确定如何将我在下面创建的自定义 objectMapper 注册为 bean,并通过构造函数或 Autowire 将其作为依赖项注入到其他对象中
@SpringBootApplication
public class DemoApplication {
@Bean
//how to register it as a bean here and inject wherever I need to via @Inject or @Autowire
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@Provider
public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {
private final ObjectMapper objectMapper = new ObjectMapper();
public ObjectMapperProvider() {
this.objectMapper.disable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
}
@Override
public ObjectMapper getContext(final Class<?> type) {
return objectMapper;
}
}
【问题讨论】:
标签: java spring spring-boot jax-rs resolver