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

SequenceWriter does not create multiple docs in a single yaml file #163

Closed
piyushkumar13 opened this issue Nov 19, 2019 · 7 comments
Closed
Labels
yaml Issue related to YAML format backend
Milestone

Comments

@piyushkumar13
Copy link

piyushkumar13 commented Nov 19, 2019

Hi,
I am trying to use SequenceWriter as suggested here to serial objects to multidocs but unsuccessful in doing do. Here is my code :

File directory = new File("src/main/resources/output");
        String fileName = "output-multidocs.yaml";

        try(SequenceWriter sequenceWriter = mapper.writer().writeValues(new File(directory, fileName))){
            sequenceWriter.init(true);
            sequenceWriter.writeAll(detailsList); // detailsList is an arrayList of object. 
            sequenceWriter.writeAll(detailsList); // Expectation is this would create separate doc in the same yaml file. But it was appending to above list.

        }catch (Exception e){
            e.printStackTrace();
        }

Could you please advice me the way to serialize objects into multidocs in a single yaml file.

@dcoraboeuf
Copy link

Can you put the stack trace you get?

@piyushkumar13
Copy link
Author

@dcoraboeuf There are no stacktraces since the above code is not throwing any exception. Its working but the second sequenceWriter.writeAll(detailsList); is appending detailsList abject in a file instead of creating new doc.

@cowtowncoder cowtowncoder added yaml Issue related to YAML format backend 2.10 labels Nov 26, 2019
@cowtowncoder
Copy link
Member

This is odd. When I try to recreate the problem, I actually get an exception (with 2.10.1).
Perhaps this is since I am trying to write main-level POJOs. Will see if array makes a difference.

But at any rate I think things are not working, even if there are different failure modes.

cowtowncoder added a commit that referenced this issue Dec 11, 2019
@piyushkumar13
Copy link
Author

@cowtowncoder I am also using 2.10.1. You can try using sequenceWriter.init(true);. Exception might resolve, since I was also getting some exception without this.

@cowtowncoder
Copy link
Member

init() is not meant to be called by anything other than ObjectWriter... I'll add Javadoc stating that. So that should not be work around.

But I think the real problem is that YAMLGenerator.close() emits both DocumentEnd and StreamEnd events (or perhaps that DocumentEnd is NOT called at close of root-level Object or Array?).

@cowtowncoder cowtowncoder added this to the 2.10.2 milestone Dec 12, 2019
@cowtowncoder cowtowncoder changed the title SequenceWriter does not create multiple docs in a single yaml file SequenceWriter does not create multiple docs in a single yaml file Dec 12, 2019
@sishbi
Copy link

sishbi commented Dec 13, 2019

Hi @cowtowncoder, Do you have an ETA for when 2.10.2 will be released?
I only just came across this issue and saw this thread which indicates that the issue is now resolved!

@cowtowncoder
Copy link
Member

@sishbi I think it should be released before end of the year, depending on when I have time to cut full minor release. So probably in 2 weeks or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
yaml Issue related to YAML format backend
Projects
None yet
Development

No branches or pull requests

4 participants