Interface DebugMode
public interface DebugMode
Interface that may be implemented by
TransientHandlers to debug the
serialization process.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SerializableA placeholder to indicate that a not serializable object should be nullified during serialization process. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanSilently checks if serialization object tracking is available on this JVM.static booleanisTrackingAvailable(org.slf4j.Logger logger) Checks if serialization object tracking is available on this JVM.default voidHook invoked when deserialization process is about to start.default voidonDeserialize(Class<?> type, Track track, Object object) Hook notified when deserialization of an object of give type is started.default ObjectonDeserialized(Object object, Track track) Tracks an object right after deserialization Implementors can provide a replacement for current processing object.default Optional<Serializable>onNotSerializableFound(Object object) Hook invoked when a notSerializableobject is found during serialization process.default voidHook invoked when serialization process is about to start.default ObjectonSerialize(Object object, Track track) Tracks an object being serialized.
-
Field Details
-
NULLIFY
A placeholder to indicate that a not serializable object should be nullified during serialization process.
-
-
Method Details
-
onSerializationStart
default void onSerializationStart()Hook invoked when serialization process is about to start. -
onNotSerializableFound
Hook invoked when a notSerializableobject is found during serialization process. Implementors can provide a serializable replacement object to preventNotSerializableExceptionor an emptyOptionalto continue processing with the input object. If an empty optional is returned, the serialization process will continue and fail fast on input Object with aNotSerializableException. To proceed the serialization process ignoring the current object, implementor can return the special valueNULLIFY. This will inform the serialization process to replace the input object with null value, avoidingNotSerializableException. In this modality, object fields will be ignored and not serialized. Default strategy is to continue processing with the current object and let the process fail withNotSerializableException.- Parameters:
object- the not serializable object instance, never null.- Returns:
- a serializable replacement for the input object or an empty Optional, never null.
- See Also:
-
onSerialize
Tracks an object being serialized. NOTE: implementation is not supposed not alter the input object, nor to throw any kind on exception.- Parameters:
object- object that is going to be serialized.
-
onDeserializationStart
default void onDeserializationStart()Hook invoked when deserialization process is about to start. -
onDeserialize
Hook notified when deserialization of an object of give type is started.- Parameters:
type- Java type of the object to deserialize.track- The tracking information for object to deserialize.
-
onDeserialized
Tracks an object right after deserialization Implementors can provide a replacement for current processing object. By default, the input object is returned.- Parameters:
object- object that is going to be serialized.
-
isTrackingAvailable
static boolean isTrackingAvailable(org.slf4j.Logger logger) Checks if serialization object tracking is available on this JVM. For it to be enabled two pre-conditions must match:- sun.io.serialization.extendedDebugInfo system property must be set to true
- reflection on
java.iopackage must be allowed through the `--add-opens` flag (e.g. '--add-opens java.base/java.io=ALL-UNNAMED')
- Parameters:
logger- logger to print hints when preconditions are not met. May be null if log is not required.- Returns:
- true if extend debug info is activated, otherwise false.
-
isTrackingAvailable
static boolean isTrackingAvailable()Silently checks if serialization object tracking is available on this JVM.- See Also:
-