Description
Spring batch version : 5.1.2
Java version : 21
First, I apologize for posting this message in English, as I am using ChatGPT for translation due to my limited English proficiency.
I have been reviewing the skip feature in Spring Batch.
I implemented the reader as a JsonItemReader and used JacksonJsonObjectReader as the jsonObjectReader.
To intentionally trigger a ParseException, I set the age field as a string, as shown below.
{
"name": "mgpark",
"email": "david.taylor@example.com",
"age": "34a",
"city": "San Francisco"
},
However, rather than skipping the error as expected, the process terminated at this point.
Upon further investigation, I observed that in JacksonJsonObjectReader.read(), an IOException results in a ParseException being thrown. However, the jsonParser token remains at the error position rather than moving to the next object. Consequently, when attempting to read the following item, jsonParser.nextToken() returns FIELD_NAME, which results in null being returned, thereby terminating the process prematurely even though there are more items to read.
To ensure that the skip functionality works correctly, it seems necessary to add a mechanism that advances the token to the next object in the event of an error.
@Nullable
public T read() throws Exception {
try {
return this.jsonParser.nextToken() == JsonToken.START_OBJECT ? this.mapper.readValue(this.jsonParser, this.itemType) : null;
} catch (IOException var2) {
IOException e = var2;
throw new ParseException("Unable to read next JSON object", e);
}
}
For reference, the job configuration I used can be found here:
RestartJob.java on GitHub
Thank you very much for your attention to this matter.