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

YamlSequence: print without extra newLine #545

Open
treblereel opened this issue Dec 8, 2022 · 5 comments
Open

YamlSequence: print without extra newLine #545

treblereel opened this issue Dec 8, 2022 · 5 comments

Comments

@treblereel
Copy link
Contributor

first of all, thank you for sure a great project ! I really love it!

So according to our specs, we should emit complex sequences without extra newLine like this:

- item    : Super Hoop
  quantity: 1
- item    : Basketball
  quantity: 4
- item    : Big Shoes
  quantity: 1

but i can't find out how to achive it:

    YamlSequenceBuilder sequence = Yaml.createYamlSequenceBuilder();

    YamlMappingBuilder compactNestedMapping = Yaml.createYamlMappingBuilder();
    compactNestedMapping = compactNestedMapping.add("item", "Super Hoop");
    compactNestedMapping = compactNestedMapping.add("quantity", "1");

    sequence = sequence.add(compactNestedMapping.build());

always produce :

-
  item: Super Hoop
  quantity: 1

i am totally sure, i do something wrong

Thanks for any ideas

@zoeself
Copy link
Collaborator

zoeself commented Dec 8, 2022

@treblereel thank you for reporting this. I'll assign someone to take care of it soon.

@zoeself
Copy link
Collaborator

zoeself commented Dec 8, 2022

@amihaiemil I couldn't find any assignee for this task. This is either because there are no contributors with role DEV available or because the project does not have enough funds.

Please, make sure there is at least one available contributor with the required role and the project can afford to pay them.

@amihaiemil amihaiemil changed the title extra newLine with compact nested mapping YamlSequence: print without extra newLine Dec 8, 2022
@amihaiemil
Copy link
Member

amihaiemil commented Dec 8, 2022

@treblereel Unfortunately, there is no way of customizing the printing logic, at the moment. There is another similar ticket and we're thinking about it. However, this is honestly speaking low prio at the moment.

But the printed YAML you get is valid, it respects the YAML spec. If some other system is consuming your YAMLs and it cannot read what is currently printed, then I think you should report a bug on their side.

Also, keep in mind that the library is based on interfaces, so you can most likely implement your own printer/visitor as a set of decorators. I think that's how we did it initially, but it became more complex when we implemented YAML Comments. If you're not interested in the comments, I think such a decorating printer should be easy to implement.

@treblereel
Copy link
Contributor Author

@amihaiemil got it, thanks a lot for the advice.

@zoeself
Copy link
Collaborator

zoeself commented Jul 4, 2023

@amihaiemil I couldn't find any assignee for this task. This is either because there are no contributors with role DEV available or because the project does not have enough funds.

Please, make sure there is at least one available contributor with the required role and the project can afford to pay them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants