Reputation: 1271
I recently attempted to use the Jackson CsvMapper and I found a peculiar "feature" that I think is a bug in the jackson lib. If I create a Spring bean for the mapper it appears to ignore the JavaTimeModule and the following error Java 8 date/time type 'java.time.*' not supported by default
I substituted the class with '*' since all of the java time classes failed. Has anyone seen this behavior before?
Here is my bean:
@Bean
fun csvMapper():CsvMapper = CsvMapper.builder()
.enable(CsvParser.Feature.TRIM_SPACES)
.enable(CsvParser.Feature.SKIP_EMPTY_LINES)
.addModule(JavaTimeModule()).build()
Here is a static instance in the class doing the processing that works as expected:
companion object {
val csvMapper: CsvMapper = CsvMapper.builder()
.enable(CsvParser.Feature.TRIM_SPACES)
.enable(CsvParser.Feature.SKIP_EMPTY_LINES)
.addModule(JavaTimeModule()).build()
}
I have tried other modules as well, such as the KotlinModule and none of them seem to be registered correctly in the bean.
Upvotes: 0
Views: 178
Reputation: 3435
How are you acquiring a reference to the Bean and the use-site?
I would bet that Spring is binding a different instance of CsvMapper
. Note that CsvMapper
is a subclass of ObjectMapper
.
In the Spring variation of your application try commenting out that that bean declaration, or debug putting a breakpoint to find the object reference for the bean you think is being used and then another breakpoint at the use-site, etc, etc.
Upvotes: 0