Fix JsonFileItemWriter to produce valid JSON when append allowed#5273
Open
quaff wants to merge 1 commit intospring-projects:mainfrom
Open
Fix JsonFileItemWriter to produce valid JSON when append allowed#5273quaff wants to merge 1 commit intospring-projects:mainfrom
quaff wants to merge 1 commit intospring-projects:mainfrom
Conversation
Contributor
|
how about when writer.setAppendAllowed(true);
writer.open(new ExecutionContext());
writer.close();
writer.open(new ExecutionContext());
writer.write(Chunk.of("ccc"));
writer.close();
resourceShouldContains("ccc"); |
Contributor
Author
Thanks for spotting, please review again. |
Contributor
|
Thank you. Minor case I found. @Test
void appendAllowed() throws Exception {
File file = Files.createTempFile("test", ".json").toFile();
WritableResource resource = new FileSystemResource(file);
Files.writeString(file.toPath(), "[\n \"foo\"]", StandardCharsets.UTF_8);
JsonFileItemWriter<String> writer =
new JsonFileItemWriter<>(resource, new JacksonJsonObjectMarshaller<>());
writer.setAppendAllowed(true);
String before = Files.readString(file.toPath(), StandardCharsets.UTF_8);
System.out.println("before:\n" + before + "\n");
System.out.println("json mapper act: " + Arrays.toString(new JsonMapper().readValue(before, String[].class)) + "\n");
writer.open(new ExecutionContext());
writer.close();
String after = new String(resource.getContentAsByteArray(), StandardCharsets.UTF_8);
System.out.println("after:\n" + after + "\n");
} |
Contributor
Author
|
JsonFileItemWriter will never generate |
Contributor
|
Okay then, I think the writer needs to validate that the existing file matches its expected format |
Closes spring-projectsGH-5272 Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
Contributor
Author
@banseok1216 I updated PR to fix this also. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes GH-5272