From 356c47c45d1ee07e227f872c968dcb9b1f98eb0d Mon Sep 17 00:00:00 2001 From: hwan33 Date: Tue, 7 Nov 2023 12:08:55 +0100 Subject: [PATCH] Update documentation about serializable keys in the execution context Resolves #4457 (cherry picked from commit dcd1ac8b521e5028088c092c2344cf968961eaec) --- spring-batch-docs/src/main/asciidoc/domain.adoc | 6 ++++++ .../org/springframework/batch/item/ExecutionContext.java | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/spring-batch-docs/src/main/asciidoc/domain.adoc b/spring-batch-docs/src/main/asciidoc/domain.adoc index c544b1053..10f78d428 100644 --- a/spring-batch-docs/src/main/asciidoc/domain.adoc +++ b/spring-batch-docs/src/main/asciidoc/domain.adoc @@ -557,6 +557,12 @@ As noted in the comment, `ecStep` does not equal `ecJob`. They are two different `ExecutionContexts`. The one scoped to the `Step` is saved at every commit point in the `Step`, whereas the one scoped to the Job is saved in between every `Step` execution. +NOTE: In the `ExecutionContext`, all non-transient entries must be `Serializable`. +Proper serialization of the execution context underpins the restart capability of steps and jobs. +Should you use keys or values that are not natively serializable, you are required to +employ a tailored serialization approach. Failing to serialize the execution context +may jeopardize the state persistence process, making failed jobs impossible to recover properly. + === JobRepository `JobRepository` is the persistence mechanism for all of the stereotypes mentioned earlier. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java index 49f0d348f..393e31da4 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java @@ -29,8 +29,9 @@ import org.springframework.lang.Nullable; * that allows optionally for type safety on reads. It also allows for dirty checking by * setting a 'dirty' flag whenever any put is called. *

- * Note that putting null value is equivalent to removing the entry for the - * given key. + * Non-transient entries should be serializable, otherwise a custom serializer should be + * used. Note that putting null value is equivalent to removing the entry for + * the given key. * * @author Lucas Ward * @author Douglas Kaminsky