spring-data-commons icon indicating copy to clipboard operation
spring-data-commons copied to clipboard

I would like to have way to deactivate constructor discovery for given classes

Open PierrickPuimeanChieze opened this issue 3 years ago • 1 comments

java version : 17 Spring data commons versions : 2.7.1

Use Case : I have a field with ZonedDateTime as type, and a mongodb codec for handling it. It work well when I write the data, but when I try to read it, I got an exception `java.lang.reflect.InaccessibleObjectException: Unable to make private java.time.ZonedDateTime(java.time.LocalDateTime,java.time.ZoneOffset,java.time.ZoneId) accessible: module java.base does not "opens java.time" to unnamed module @11bb571c``

After analysis, it come from the fact that the constructor discovery mechanism try to make the only constructor for ZonedDateTime accessible, which can not work.

The sad thing is that the converter mechanism can make use of codec, but only if it can't found a suitable constructor.

One solution would be to be able to indicate somewhere some classes which must no be initialize by constructor. Or to indicate that private constructor must be ignored for some classes

PierrickPuimeanChieze avatar Oct 13 '22 08:10 PierrickPuimeanChieze

If you use ZonedDateTime then please register a custom converter in which you specify how to map ZonedDateTime in MongoDB.

mp911de avatar Oct 13 '22 14:10 mp911de

Maybe related to https://github.com/spring-projects/spring-data-mongodb/issues/4204

mp911de avatar Oct 17 '22 14:10 mp911de