-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Is your feature request related to a problem? Please describe.
I'm trying to run a service compiled with GraalVM into a native image. The service does not reference or create HashSet
explicitly and uses Set
in all DTOs instead. Upon deserialization, an exception happens that says that "java.util.HashSet can't be created because no creator, like default constructor, exists". Those are removed by dead code elimination as none are registered for reflection or used explicitly, and ContainerDefaultMappings
provides just a class reference that is used later to create a given set via newInstance
.
Describe the solution you'd like
My current solution using Spring Boot is to simply register these classes for reflection:
hints.reflection()
.registerTypes(TypeReference.listOf(
ArrayList.class,
LinkedList.class,
HashSet.class,
TreeSet.class,
ConcurrentHashMap.class,
LinkedHashMap.class,
TreeMap.class),
TypeHint.builtWith(INVOKE_PUBLIC_CONSTRUCTORS, INVOKE_PUBLIC_METHODS));
This is not perfect, though.
Another approach might be to create appropriate value instantiators in JDKValueInstantiators
for every fallback collection as they specifically tell what constructor will be used.
Usage example
No response
Additional context
No response