-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow (de)serializing records using Bean(De)SerializerModifier
even when reflection is unavailable
#3417
Merged
Merged
Allow (de)serializing records using Bean(De)SerializerModifier
even when reflection is unavailable
#3417
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
92504ce
Fail gracefully when record components are missing in native image
yawkat 794aa3b
fix error in RecordNaming as well
yawkat 6f828ef
Error message improvements for native image
yawkat 7eae58c
Use System.getProperty instead of the graal-sdk dependency
yawkat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
62 changes: 62 additions & 0 deletions
62
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,62 @@ | ||
package com.fasterxml.jackson.databind.util; | ||
|
||
import org.graalvm.nativeimage.ImageInfo; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
/** | ||
* Utilities for graal native image support. | ||
*/ | ||
public class NativeImageUtil { | ||
private static final boolean RUNNING_IN_SVM; | ||
|
||
static { | ||
yawkat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
boolean runningInSvm; | ||
try { | ||
// check whether ImageInfo is available | ||
ImageInfo.inImageCode(); | ||
runningInSvm = true; | ||
} catch (NoClassDefFoundError ignored) { | ||
runningInSvm = false; | ||
} | ||
RUNNING_IN_SVM = runningInSvm; | ||
} | ||
|
||
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 && ImageInfo.inImageRuntimeCode(); | ||
} | ||
|
||
/** | ||
* 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; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a brief comment referring to this PR, purpose.