0
如何在Spring中將yml
文件中的屬性設置爲DEFAULT_VIEW_INCLUSION
?在YAML文件中設置DEFAULT_VIEW_INCLUSION
現在,我有這個
spring: jackson: mapper: DEFAULT_VIEW_INCLUSION: true
但不起作用。
如何在Spring中將yml
文件中的屬性設置爲DEFAULT_VIEW_INCLUSION
?在YAML文件中設置DEFAULT_VIEW_INCLUSION
現在,我有這個
spring: jackson: mapper: DEFAULT_VIEW_INCLUSION: true
但不起作用。
嘗試用Java的配置:
@Configuration
public class JacksonMapperConfig {
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
return mapper;
}
}
如果你使用Spring的引導,就可以自動裝配的ObjectMapper:
@Configuration
public class JacksonConfig {
@Autowired
private ObjectMapper objectMapper;
@PostConstruct
public void configureObjectMapper() {
objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
}
}
謝謝,夥計! :) –