Skip to content

JsonItemReaderBuilder should not substitute null resource with ByteArrayResource #5234

Closed

Description

@banseok1216

Environment
Spring Batch 6.0.2

Expected Behavior

JsonItemReaderBuilder should not replace a null resource with an empty ByteArrayResource. It should align with the “resource can be injected later” pattern used with FlatFileItemReader, especially when the reader is used as a delegate of MultiResourceItemReader.

if (this.resource == null) {
    logger.debug("The resource is null. This is only a valid scenario when "
            + "injecting it later as in when using the MultiResourceItemReader");
}

JsonItemReader<T> reader = new JsonItemReader<>(this.jsonObjectReader);
reader.setResource(this.resource);
return reader;

Current Behavior

When resource == null, the builder replaces it with an empty ByteArrayResource and creates the reader with that placeholder.

if (this.resource == null) {
    this.resource = new ByteArrayResource(new byte[0]);
}
JsonItemReader<T> reader = new JsonItemReader<>(this.resource, this.jsonObjectReader);

Context

Keep the resource null in the builder and let the reader validate it at doOpen time (as FlatFileItemReader does), instead of inserting an empty placeholder resource.

Activity

  1. added this to the 6.0.4 milestone on Jun 4, 2026
  2. added a commit that references this issue on Jun 4, 2026
    61286ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions