Class DefaultJobParametersConverter
java.lang.Object
org.springframework.batch.core.converter.DefaultJobParametersConverter
- All Implemented Interfaces:
JobParametersConverter
Converter for
If you need to be able to parse and format local-specific dates and numbers, you can inject formatters (
JobParameters
instances that uses a simple naming convention for
property keys. Key names that are prefixed with a -
are considered
non-identifying and do not contribute to the identity of a JobInstance
. Key
names ending with "(<type>)" (where type is one of string, date, long) are
converted to the corresponding type. The default type is string. Consider the following
example:
schedule.date(date)=2007/12/11 department.id(long)=2345The literal values are converted to the correct type by using the default Spring strategies, augmented if necessary by any custom editors that have been provided.
If you need to be able to parse and format local-specific dates and numbers, you can inject formatters (
setDateFormat(DateFormat)
and
setNumberFormat(NumberFormat)
).- Author:
- Dave Syer, Michael Minella, Mahmoud Ben Hassine
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Parameter key suffix representing the date type.static final String
Parameter key suffix representing the double type.static final String
Parameter key suffix representing the long type.static final String
Parameter key suffix representing the string type. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetJobParameters
(Properties props) Check for a suffix on keys and use those to decide how to convert the value.getProperties
(JobParameters params) Use the same suffixes to create properties (omitting the string suffix because it is the default).void
setDateFormat
(DateFormat dateFormat) Public setter for injecting a date format.void
setNumberFormat
(NumberFormat numberFormat) Public setter for theNumberFormat
.
-
Field Details
-
DATE_TYPE
Parameter key suffix representing the date type.- See Also:
-
STRING_TYPE
Parameter key suffix representing the string type.- See Also:
-
LONG_TYPE
Parameter key suffix representing the long type.- See Also:
-
DOUBLE_TYPE
Parameter key suffix representing the double type.- See Also:
-
-
Constructor Details
-
DefaultJobParametersConverter
public DefaultJobParametersConverter()
-
-
Method Details
-
getJobParameters
Check for a suffix on keys and use those to decide how to convert the value.- Specified by:
getJobParameters
in interfaceJobParametersConverter
- Parameters:
props
- The runtime parameters in the form of String literals.- Returns:
- a
JobParameters
object converted to the correct types. - Throws:
IllegalArgumentException
- if a number or date is passed in that cannot be parsed or cast to the correct type.- See Also:
-
getProperties
Use the same suffixes to create properties (omitting the string suffix because it is the default). Non-identifying parameters are prefixed with theNON_IDENTIFYING_FLAG
. However, since parameters are identifying by default, they are not prefixed with theIDENTIFYING_FLAG
.- Specified by:
getProperties
in interfaceJobParametersConverter
- Parameters:
params
- TheJobParameters
instance to be converted.- Returns:
- a representation of the parameters as properties.
- See Also:
-
setDateFormat
Public setter for injecting a date format.- Parameters:
dateFormat
- ADateFormat
, defaults to "yyyy/MM/dd".
-
setNumberFormat
Public setter for theNumberFormat
. Used to parse longs and doubles, so must not contain decimal place (for example, use "#" or "#,###" but not "#.##").- Parameters:
numberFormat
- theNumberFormat
to set
-