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

Micronaut fails for LocalDateTime method parameter #9969

Closed
rlconst opened this issue Oct 12, 2023 · 9 comments
Closed

Micronaut fails for LocalDateTime method parameter #9969

rlconst opened this issue Oct 12, 2023 · 9 comments

Comments

@rlconst
Copy link

rlconst commented Oct 12, 2023

Expected Behavior

You can pass LocalDateTime as parameter

String localDateTime(@NotNull @QueryValue LocalDateTime time) {
    ...
}

Actual Behaviour

ERROR i.m.r.intercept.RecoveryInterceptor - Type [io.micronaut.http.client.convert.DateTimeConversionSpec$TimeClient$Intercepted] executed with error: Unsupported field: OffsetSeconds
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: OffsetSeconds
	at java.base/java.time.LocalDate.get0(LocalDate.java:709)
	at java.base/java.time.LocalDate.getLong(LocalDate.java:688)
	at java.base/java.time.LocalDateTime.getLong(LocalDateTime.java:718)
	at java.base/java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:308)
	at java.base/java.time.format.DateTimeFormatterBuilder$OffsetIdPrinterParser.format(DateTimeFormatterBuilder.java:3628)
	at java.base/java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2402)
	at java.base/java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1849)
	at java.base/java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1823)
	at io.micronaut.runtime.converters.time.TimeConverterRegistrar.lambda$register$3(TimeConverterRegistrar.java:141)
	at io.micronaut.core.convert.DefaultConversionService.convert(DefaultConversionService.java:155)
	at io.micronaut.context.env.DefaultEnvironment.convert(DefaultEnvironment.java:311)
	at io.micronaut.core.convert.ConversionService.convert(ConversionService.java:120)
	at io.micronaut.http.client.bind.binders.QueryValueClientArgumentRequestBinder.bind(QueryValueClientArgumentRequestBinder.java:119)

Steps To Reproduce

No response

Environment Information

No response

Example Application

No response

Version

3.10.1

@rlconst
Copy link
Author

rlconst commented Oct 12, 2023

I'm on 3.10.x and I did a simple fix. 4.x logic is significantly different. What is the best aproach: backport or keep it as is?

@sdelamo
Copy link
Contributor

sdelamo commented Oct 26, 2023

This does not happen in Micronaut Framework 4, does it?

@sdelamo
Copy link
Contributor

sdelamo commented Oct 26, 2023

@rlconst I am not able to reproduce this with @QueryValue or FormUrlEncoded body

#10027

what am I missing to reproduce it @rlconst ?

@yawkat
Copy link
Member

yawkat commented Oct 26, 2023

ok looking at the 3.x code it seems this is an issue because youre trying to return an LDT in a format that needs an offset. imo it is correct that this fails and this is not a bug.

@rlconst
Copy link
Author

rlconst commented Oct 27, 2023

@sdelamo the problem is on Micronaut 3.10.1. On 4.x LocalDateTime handled properly. To reproduce the problem, just copy test-case without fix and you should see

@rlconst
Copy link
Author

rlconst commented Oct 27, 2023

@yawkat passing data with fake offset (UTC) is for minimizing changes in code. I disagree that HTTP Client should fail because it can't correctly serialize and deserialize some class from the core JDK because for some reason it decided that you can't pass timestamp without offset.

@yawkat
Copy link
Member

yawkat commented Oct 27, 2023

We should not hallucinate a time zone. If you want to produce a string that contains a zone/offset, you must use a type that includes the offset.

@rlconst
Copy link
Author

rlconst commented Oct 27, 2023

@yawkat I want to be able to pass LocalDateTime as @RequestParam and I don't care about offsets and timezones

@sdelamo
Copy link
Contributor

sdelamo commented Nov 1, 2023

I think this can be closed via #10027

@sdelamo sdelamo closed this as completed Nov 1, 2023
@github-project-automation github-project-automation bot moved this to Done in 4.1.6 Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants