Open ckosmowski opened 4 years ago
The Workaround with providing a custom format with @Format annotation does not work either. Because we can only provide a string here:
@param:Format("yyyy-MM-dd'T'HH:mm:ss")
var serviceDate: LocalDateTime? = null,
we are unable to express that the seconds are optional.
Please provide an example that reproduces the issue
Okay, do you have a Kafka Cluster to test with? We have this problem when consuming messages from kafka.
I was able to isolate the core problem from the kafka stuff.
The Kafka Consumer (from micronaut-kafka) at some point in the consuming process uses:
ConversionService.SHARED.convert(sourceData, context)
. And that's where our journey begins.
Please see:
https://github.com/ckosmowski/micronaut-examples/tree/issues/core/2972
It contains a test ConvertTest
that showcases the different things we tried.
It seems like it is important that the converted class has constructor arguments.
Unfortunately we still have to do several workarounds because of this issue. Is there any chance that this will make it to a milestone soon?
@ckosmowski PRs welcome
https://github.com/micronaut-projects/micronaut-core/blob/ae5430bfec4cd2fe838e2df874509b0403158795/runtime/src/main/java/io/micronaut/runtime/converters/time/TimeConverterRegistrar.java#L210-L214
We use micronaut-kafka to deserialize JSON messages to Java Objects. We are also (recently) using the micronaut-validation mechanism for bean validation on these Java Beans.
However since we annotated our beans with "@Introspected" it is not possible anymore to deserialize Json Objects contains LocalDateTime objects. The Strings in our JSON are formatted in ISO format (Like LocalDateTime.parse is able to parse).
Since we added @Introspected the whole code seems to take a different way through execution and goes through the above snippet which uses a totally different Formatter than the Jackson Formatter does that is used in Micronaut Kafka or in the kafka HTTP Server.
It seems to me, that the default format should be ISO, or otherwise when parsing Strings to LocalDateTime here:
https://github.com/micronaut-projects/micronaut-core/blob/ae5430bfec4cd2fe838e2df874509b0403158795/runtime/src/main/java/io/micronaut/runtime/converters/time/TimeConverterRegistrar.java#L134-L136
the formatter should not be used.
Anyway with the @Introspected we get very different results than without it.