Class DefaultJobParametersConverter
- java.lang.Object
- org.springframework.batch.core.converter.DefaultJobParametersConverter
- All Implemented Interfaces:
JobParametersConverter
public class DefaultJobParametersConverter extends java.lang.Object implements JobParametersConverter
Converter forJobParameters
instances using a simple naming convention for property keys. Key names that are prefixed with a - are considered non-identifying and will not contribute to the identity of aJobInstance
. Key names ending with "(<type>)" where type is one of string, date, long are converted to the corresponding type. The default type is string. E.g.schedule.date(date)=2007/12/11 department.id(long)=2345
The literal values are converted to the correct type using the default Spring strategies, augmented if necessary by the custom editors provided.
If you need to be able to parse and format local-specific dates and numbers, you can inject formatters (setDateFormat(DateFormat)
andsetNumberFormat(NumberFormat)
).- Author:
- Dave Syer, Michael Minella, Mahmoud Ben Hassine
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DATE_TYPE
static java.lang.String
LONG_TYPE
static java.lang.String
STRING_TYPE
Constructor Summary
Constructors Constructor Description DefaultJobParametersConverter()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JobParameters
getJobParameters(java.util.Properties props)
Check for suffix on keys and use those to decide how to convert the value.java.util.Properties
getProperties(JobParameters params)
Use the same suffixes to create properties (omitting the string suffix because it is the default).void
setDateFormat(java.text.DateFormat dateFormat)
Public setter for injecting a date format.void
setNumberFormat(java.text.NumberFormat numberFormat)
Public setter for theNumberFormat
.
Field Detail
DATE_TYPE
public static final java.lang.String DATE_TYPE
- See Also:
- Constant Field Values
STRING_TYPE
public static final java.lang.String STRING_TYPE
- See Also:
- Constant Field Values
LONG_TYPE
public static final java.lang.String LONG_TYPE
- See Also:
- Constant Field Values
Method Detail
getJobParameters
public JobParameters getJobParameters(@Nullable java.util.Properties props)
Check for 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
properties converted to the correct types. - Throws:
java.lang.IllegalArgumentException
- if a number or date is passed in that cannot be parsed, or cast to the correct type.- See Also:
JobParametersConverter.getJobParameters(java.util.Properties)
getProperties
public java.util.Properties getProperties(@Nullable JobParameters params)
Use the same suffixes to create properties (omitting the string suffix because it is the default). Non-identifying parameters will be prefixed with theNON_IDENTIFYING_FLAG
. However, since parameters are identifying by default, they will not be 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:
JobParametersConverter.getProperties(org.springframework.batch.core.JobParameters)
setDateFormat
public void setDateFormat(java.text.DateFormat dateFormat)
Public setter for injecting a date format.- Parameters:
dateFormat
- aDateFormat
, defaults to "yyyy/MM/dd"
setNumberFormat
public void setNumberFormat(java.text.NumberFormat numberFormat)
Public setter for theNumberFormat
. Used to parse longs and doubles, so must not contain decimal place (e.g. use "#" or "#,###").- Parameters:
numberFormat
- theNumberFormat
to set