Class JsonJobParametersConverter
java.lang.Object
org.springframework.batch.core.converter.DefaultJobParametersConverter
org.springframework.batch.core.converter.JsonJobParametersConverter
- All Implemented Interfaces:
JobParametersConverter
Converter for
JobParameters
instances that uses a JSON naming convention for
converting job parameters. The expected notation is the following:
key='{"value": "parameterStringLiteralValue", "type":"fully.qualified.name.of.the.parameter.Type", "identifying": "booleanValue"}'
where:
- value: string literal representing the value
- type (optional): fully qualified name of the type of the value. Defaults to String.
- identifying (optional): boolean to flag the job parameter as identifying or not. Defaults to true
LocalDate
with value "2022-12-12".
The literal values are converted to the correct type by using the default Spring conversion service, augmented if necessary by any custom converters. The conversion service should be configured with a converter to and from string literals to job parameter types.
By default, the Spring conversion service is augmented to support the conversion of the following types:
Date
: in theDateTimeFormatter.ISO_INSTANT
formatLocalDate
: in theDateTimeFormatter.ISO_LOCAL_DATE
formatLocalTime
: in theDateTimeFormatter.ISO_LOCAL_TIME
formatLocalDateTime
: in theDateTimeFormatter.ISO_LOCAL_DATE_TIME
format
- Since:
- 5.0
- Author:
- Mahmoud Ben Hassine
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
-
Field Summary
Fields inherited from class org.springframework.batch.core.converter.DefaultJobParametersConverter
conversionService
-
Constructor Summary
ConstructorDescriptionCreate a newJsonJobParametersConverter
with a defaultObjectMapper
.JsonJobParametersConverter
(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Create a newJsonJobParametersConverter
with a customObjectMapper
. -
Method Summary
Modifier and TypeMethodDescriptionprotected JobParameter
Decode a job parameter from a string.protected String
encode
(JobParameter<?> jobParameter) Encode a job parameter to a string.Methods inherited from class org.springframework.batch.core.converter.DefaultJobParametersConverter
getJobParameters, getProperties, setConversionService
-
Constructor Details
-
JsonJobParametersConverter
public JsonJobParametersConverter()Create a newJsonJobParametersConverter
with a defaultObjectMapper
. -
JsonJobParametersConverter
public JsonJobParametersConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Create a newJsonJobParametersConverter
with a customObjectMapper
.- Parameters:
objectMapper
- the object mapper to use
-
-
Method Details
-
encode
Description copied from class:DefaultJobParametersConverter
Encode a job parameter to a string.- Overrides:
encode
in classDefaultJobParametersConverter
- Parameters:
jobParameter
- the parameter to encode- Returns:
- the encoded job parameter
-
decode
Description copied from class:DefaultJobParametersConverter
Decode a job parameter from a string.- Overrides:
decode
in classDefaultJobParametersConverter
- Parameters:
encodedJobParameter
- the encoded job parameter- Returns:
- the decoded job parameter
-