Skip to content

JsonFileItemWriter writes invalid json when write method called few times in a row. [BATCH-2752] #852

@spring-projects-issues

Description

@spring-projects-issues

gd-estrepetov opened BATCH-2752 and commented

JsonFileItemWriter adds unnecessary "," when data is written in chunks to json file.

Code to reproduce:

List<String> firstList = Arrays.asList("one", "two");
List<String> secondList = Arrays.asList("three", "four");

JsonFileItemWriter<String> writer = new JsonFileItemWriterBuilder<String>()
        .name("writer")
        .resource(new FileSystemResource("test.json"))
        .jsonObjectMarshaller(new JacksonJsonObjectMarshaller<>())
        .build();

writer.open(new ExecutionContext());
writer.write(firstList);
writer.write(secondList);

writer.close();

Result:

[
 "one",
 "two",
 "three",
,
 "four"
]

Affects: 4.1.0.M3

Referenced from: pull request #636

Backported to: 4.1.0.RC1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions