Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Java 8 date/time type LocalDateTime not supported by default #2486

Closed
wants to merge 2 commits into from

Conversation

yuluo-yx
Copy link
Contributor

@yuluo-yx yuluo-yx commented Aug 7, 2024

@pwallk
Copy link
Contributor

pwallk commented Aug 7, 2024

Perhaps adding jackson-datatype-jsr310 would be a better choice,such as

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer customizer() {
        return builder -> {
            JavaTimeModule javaTimeModule = new JavaTimeModule();
            final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
            simpleDateFormat.setTimeZone(TimeZone.getDefault());

            javaTimeModule.addSerializer(BigDecimal.class, ToStringSerializer.instance);
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");
            javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter));
            javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter));

            builder.modules(javaTimeModule)
                    .timeZone(TimeZone.getDefault())
                    .dateFormat(simpleDateFormat)
        };
    }

@yuluo-yx
Copy link
Contributor Author

yuluo-yx commented Aug 7, 2024

Perhaps adding jackson-datatype-jsr310 would be a better choice,such as

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer customizer() {
        return builder -> {
            JavaTimeModule javaTimeModule = new JavaTimeModule();
            final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
            simpleDateFormat.setTimeZone(TimeZone.getDefault());

            javaTimeModule.addSerializer(BigDecimal.class, ToStringSerializer.instance);
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");
            javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter));
            javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter));

            builder.modules(javaTimeModule)
                    .timeZone(TimeZone.getDefault())
                    .dateFormat(simpleDateFormat)
        };
    }

Have you tested this locally to see if it works?

@yuluo-yx
Copy link
Contributor Author

yuluo-yx commented Aug 7, 2024

btw, This doesn't look like it's going to work. Maybe you have a better plan.
image

@pwallk
Copy link
Contributor

pwallk commented Aug 7, 2024

The example is rough, DateTimeFormatter does not support yyyy-MM-dd'T 'hh :mm:ss.SSSX, change to yyyy-MM-dd'T'HH:mm:ss.SSSSSS

@yuluo-yx
Copy link
Contributor Author

yuluo-yx commented Aug 7, 2024

The example is rough, DateTimeFormatter does not support yyyy-MM-dd'T 'hh :mm:ss.SSSX, change to yyyy-MM-dd'T'HH:mm:ss.SSSSSS

In the demo you provided, the time format is also. And the previous code was in this date format, is there any advantage to changing it?
image

@pwallk
Copy link
Contributor

pwallk commented Aug 7, 2024

Just to demonstrate how jackson supports LocalDateTime, the time format can be changed as needed,

@yuluo-yx
Copy link
Contributor Author

yuluo-yx commented Aug 7, 2024

Just to demonstrate how jackson supports LocalDateTime, the time format can be changed as needed,

cc @tomsun28. Do you have any ideas for this pr

@Calvin979 Calvin979 changed the title [type:bugfix] Java 8 date/time type LocalDateTime not supported by default [bugfix] Java 8 date/time type LocalDateTime not supported by default Aug 7, 2024
@Calvin979
Copy link
Contributor

@yuluo-yx Maybe you can refer #2122 to find out why LocalDateTime is supported by default.
Is the time correct in db on your pr?

@tomsun28
Copy link
Contributor

tomsun28 commented Aug 7, 2024

hi, this also related the pr #2251

@yuluo-yx
Copy link
Contributor Author

yuluo-yx commented Aug 7, 2024

hi, this also related the pr #2251

Looks like there's a lot riding on this one. 🥲🥲

@yuluo-yx
Copy link
Contributor Author

I'm going to close this pr for now, looking for a better solution in #2454

@yuluo-yx yuluo-yx closed this Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants