Closed vince-0202 closed 1 year ago
Jackson loads a small number of its less commonly used serializers using reflection. Without some additional metadata, these serializers cannot be loaded in a native image. You could fix your problem by providing some reflection hints that allow SqlDateSerializer
to be loaded and instantiated through reflection.
I'll transfer this issue to the Framework team as they may want to consider automatically adding the necessary reflection hints when org.springframework.aot.hint.annotation.RegisterReflectionForBindingProcessor
detects that a java.sql.Date
will be serialized and that Jackson's in use.
Jackson loads a small number of its less commonly used serializers using reflection. Without some additional metadata, these serializers cannot be loaded in a native image. You could fix your problem by providing some reflection hints that allow
SqlDateSerializer
to be loaded and instantiated through reflection.
@wilkinsona THX!!! My problem was solved when I added the following configuration
@ImportRuntimeHints(SqlDateSerializerRuntimeHintsConfig.SqlDateSerializerRuntimeHints.class)
public class SqlDateSerializerRuntimeHintsConfig {
static class SqlDateSerializerRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
for (Constructor<?> constructor : SqlDateSerializer.class.getConstructors()) {
hints.reflection().registerConstructor(constructor,ExecutableMode.INVOKE);
}
}
}
}
I'll transfer this issue to the Framework team as they may want to consider automatically adding the necessary reflection hints when
org.springframework.aot.hint.annotation.RegisterReflectionForBindingProcessor
detects that ajava.sql.Date
will be serialized and that Jackson's in use.That's great!!!
It could be interesting to explore if OptionalHandlerFactory
can be used in BindingReflectionHintsRegistrar#registerJacksonHints
(with proper classpath check) to support the various serializers/deserializers listed there.
After a deeper look, since those hints are not very dynamic and can take advantage of conditionalOnType
, I think it will be better to support those on https://github.com/oracle/graalvm-reachability-metadata side. I will create a related PR that I will link in a comment.
Hi,I got a problem when my spring-boot program running with native image. It can't serializer
java.sql.Date
caus classcom.fasterxml.jackson.databind.ser.std.SqlDateSerializer
not found.It only happend in native image.if my program don't running in native image,it works well.Here is the response from my program which running in native image and the struct of the task field.Other types of fields are fine.
What I use
And the follow is my gradle.build, did I write something wrong?