|
1 | 1 | /*
|
2 |
| - * Copyright 2022 the original author or authors. |
| 2 | + * Copyright 2022-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
15 | 15 | */
|
16 | 16 | package org.springframework.batch.core.converter;
|
17 | 17 |
|
18 |
| -import java.io.IOException; |
19 |
| - |
20 |
| -import com.fasterxml.jackson.core.JsonParser; |
21 | 18 | import com.fasterxml.jackson.core.JsonProcessingException;
|
22 |
| -import com.fasterxml.jackson.databind.MappingJsonFactory; |
23 | 19 | import com.fasterxml.jackson.databind.ObjectMapper;
|
24 | 20 |
|
25 | 21 | import org.springframework.batch.core.JobParameter;
|
26 | 22 | import org.springframework.batch.core.JobParameters;
|
27 |
| -import org.springframework.util.StringUtils; |
28 | 23 |
|
29 | 24 | /**
|
30 | 25 | * Converter for {@link JobParameters} instances that uses a JSON naming convention for
|
|
36 | 31 | * where:
|
37 | 32 | *
|
38 | 33 | * <ul>
|
39 |
| - * <li>value: string literal repesenting the value</li> |
| 34 | + * <li>value: string literal representing the value</li> |
40 | 35 | * <li>type (optional): fully qualified name of the type of the value. Defaults to
|
41 | 36 | * String.</li>
|
42 | 37 | * <li>identifying (optional): boolean to flag the job parameter as identifying or not.
|
|
58 | 53 | */
|
59 | 54 | public class JsonJobParametersConverter extends DefaultJobParametersConverter {
|
60 | 55 |
|
61 |
| - private ObjectMapper objectMapper = new ObjectMapper(); |
| 56 | + private final ObjectMapper objectMapper; |
62 | 57 |
|
63 | 58 | /**
|
64 | 59 | * Create a new {@link JsonJobParametersConverter} with a default
|
@@ -96,7 +91,10 @@ protected JobParameter decode(String encodedJobParameter) {
|
96 | 91 | try {
|
97 | 92 | JobParameterDefinition jobParameterDefinition = this.objectMapper.readValue(encodedJobParameter,
|
98 | 93 | JobParameterDefinition.class);
|
99 |
| - Class<?> parameterType = Class.forName(jobParameterDefinition.type()); |
| 94 | + Class<?> parameterType = String.class; |
| 95 | + if (jobParameterDefinition.type() != null) { |
| 96 | + parameterType = Class.forName(jobParameterDefinition.type()); |
| 97 | + } |
100 | 98 | boolean parameterIdentifying = true;
|
101 | 99 | if (jobParameterDefinition.identifying() != null && !jobParameterDefinition.identifying().isEmpty()) {
|
102 | 100 | parameterIdentifying = Boolean.valueOf(jobParameterDefinition.identifying());
|
|
0 commit comments