gpt4 book ai didi

java - Jackson如何自动获取模块bean?

转载 作者:行者123 更新时间:2023-12-03 08:19:33 25 4
gpt4 key购买 nike

我正在上以下课

@SpringBootApplication
public class TestApplication {

public static void main(final String[] args) {

SpringApplication.run(TestApplication.class, args);
}

@Bean
public Module jdk8Module() {
return new Jdk8Module();
}

@Bean
public Module guavaModule() {
return new GuavaModule();
}
}

这里这两个bean自动注册到jackson ObjectMapper中。它是如何自动注册这个模块的?

最佳答案

这是由 Spring Boot JacksonAutoConfiguration 完成的类。

正如 javadoc 所说:

Auto configuration for Jackson. The following auto-configuration will get applied:

  • an ObjectMapper in case none is already configured.
  • a Jackson2ObjectMapperBuilder in case none is already configured.
  • auto-registration for all Module beans with all ObjectMapper beans (including the defaulted ones).

关于java - Jackson如何自动获取模块bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68297578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com