quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.53k stars 2.61k forks source link

Improve native-image documentation for Serialization registration #41997

Open Sanne opened 1 month ago

Sanne commented 1 month ago

Description

I was having native-image spit out errors:

com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor class not found for declaringClass: java.lang.String (targetConstructorClass: java.lang.Object). Usually adding java.lang.String to serialization-config.json fixes the problem

It turns out the fix is trivial, as apparently one can contribute entries to the serialization-config.json by using

@RegisterForReflection(targets = { String.class }, serialization = true)

Unfortunately the guide at https://quarkus.io/guides/writing-native-applications-tips doesn't mention neither the serialization-config.json and the serialization attribute of @RegisterForReflection.

Implementation ideas

It would be nice to add a section, especially keeping in mind the language used by the GraalVM native-image error: while we don't normally expect people to create files such as serialization-config.json, I suspect they will be searching for related instructions.

quarkus-bot[bot] commented 1 month ago

/cc @zakkak (native-image)

zakkak commented 1 month ago

Regarding serialization-config.json please note that it's going to be deprecated in GraalVM for JDK 23 and replaced by reachability-metadata.json see https://github.com/oracle/graal/pull/9048, related Quarkus issue https://github.com/quarkusio/quarkus/issues/41016