diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/converter/JsonJobParametersConverter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/converter/JsonJobParametersConverter.java
index 63060fa24..d51c10b15 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/converter/JsonJobParametersConverter.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/converter/JsonJobParametersConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 the original author or authors.
+ * Copyright 2022-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,16 +15,11 @@
*/
package org.springframework.batch.core.converter;
-import java.io.IOException;
-
-import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.MappingJsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParameters;
-import org.springframework.util.StringUtils;
/**
* Converter for {@link JobParameters} instances that uses a JSON naming convention for
@@ -36,7 +31,7 @@ import org.springframework.util.StringUtils;
* where:
*
*
- * - value: string literal repesenting the value
+ * - 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.
@@ -58,7 +53,7 @@ import org.springframework.util.StringUtils;
*/
public class JsonJobParametersConverter extends DefaultJobParametersConverter {
- private ObjectMapper objectMapper = new ObjectMapper();
+ private final ObjectMapper objectMapper;
/**
* Create a new {@link JsonJobParametersConverter} with a default
@@ -96,7 +91,10 @@ public class JsonJobParametersConverter extends DefaultJobParametersConverter {
try {
JobParameterDefinition jobParameterDefinition = this.objectMapper.readValue(encodedJobParameter,
JobParameterDefinition.class);
- Class> parameterType = Class.forName(jobParameterDefinition.type());
+ Class> parameterType = String.class;
+ if (jobParameterDefinition.type() != null) {
+ parameterType = Class.forName(jobParameterDefinition.type());
+ }
boolean parameterIdentifying = true;
if (jobParameterDefinition.identifying() != null && !jobParameterDefinition.identifying().isEmpty()) {
parameterIdentifying = Boolean.valueOf(jobParameterDefinition.identifying());
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/converter/JsonJobParametersConverterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/converter/JsonJobParametersConverterTests.java
index 286e761ac..82b168b05 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/converter/JsonJobParametersConverterTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/converter/JsonJobParametersConverterTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 the original author or authors.
+ * Copyright 2022-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -85,4 +85,20 @@ class JsonJobParametersConverterTests {
Assertions.assertTrue(jobParameter.isIdentifying());
}
+ @Test
+ void testDecodeWithDefaultIdentifyingFlagAndDefaultType() {
+ // given
+ JsonJobParametersConverter converter = new JsonJobParametersConverter();
+ String encodedJobParameter = "{\"value\":\"foo\"}";
+
+ // when
+ JobParameter jobParameter = converter.decode(encodedJobParameter);
+
+ // then
+ Assertions.assertNotNull(jobParameter);
+ Assertions.assertEquals("foo", jobParameter.getValue());
+ Assertions.assertEquals(String.class, jobParameter.getType());
+ Assertions.assertTrue(jobParameter.isIdentifying());
+ }
+
}
\ No newline at end of file