Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Skip Functionality on ParseException in JacksonJsonObjectReader #4701

Open
mgpark-korean opened this issue Nov 7, 2024 · 0 comments
Labels
status: waiting-for-triage Issues that we did not analyse yet type: bug

Comments

@mgpark-korean
Copy link

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.

@mgpark-korean mgpark-korean added status: waiting-for-triage Issues that we did not analyse yet type: bug labels Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage Issues that we did not analyse yet type: bug
Projects
None yet
Development

No branches or pull requests

1 participant