-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow (de)serializing records using
Bean(De)SerializerModifier
even…
… when reflection is unavailable (#3417)
- Loading branch information
Showing
6 changed files
with
128 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/fasterxml/jackson/databind/util/NativeImageUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.fasterxml.jackson.databind.util; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
/** | ||
* Utilities for graal native image support. | ||
*/ | ||
public class NativeImageUtil { | ||
private static final boolean RUNNING_IN_SVM; | ||
|
||
static { | ||
RUNNING_IN_SVM = System.getProperty("org.graalvm.nativeimage.imagecode") != null; | ||
} | ||
|
||
private NativeImageUtil() { | ||
} | ||
|
||
/** | ||
* Check whether we're running in substratevm native image runtime mode. This check cannot be a constant, because | ||
* the static initializer may run early during build time | ||
*/ | ||
private static boolean isRunningInNativeImage() { | ||
return RUNNING_IN_SVM && System.getProperty("org.graalvm.nativeimage.imagecode").equals("runtime"); | ||
} | ||
|
||
/** | ||
* Check whether the given error is a substratevm UnsupportedFeatureError | ||
*/ | ||
public static boolean isUnsupportedFeatureError(Throwable e) { | ||
if (!isRunningInNativeImage()) { | ||
return false; | ||
} | ||
if (e instanceof InvocationTargetException) { | ||
e = e.getCause(); | ||
} | ||
return e.getClass().getName().equals("com.oracle.svm.core.jdk.UnsupportedFeatureError"); | ||
} | ||
|
||
/** | ||
* Check whether the given class is likely missing reflection configuration (running in native image, and no | ||
* members visible in reflection). | ||
*/ | ||
public static boolean needsReflectionConfiguration(Class<?> cl) { | ||
if (!isRunningInNativeImage()) { | ||
return false; | ||
} | ||
// records list their fields but not other members | ||
return (cl.getDeclaredFields().length == 0 || ClassUtil.isRecordType(cl)) && | ||
cl.getDeclaredMethods().length == 0 && | ||
cl.getDeclaredConstructors().length == 0; | ||
} | ||
} |