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

Implement option to write sequences out in flow stlye for only certain fields with primitive arrays #9

Closed
szahn opened this issue Dec 8, 2012 · 13 comments
Assignees

Comments

@szahn
Copy link

szahn commented Dec 8, 2012

Sequences are currently being written out as blocks. There should be a public variable in the emitter to set the style to flow on certain fields that hold arrays with primitive values.

See http://yaml.org/spec/1.0/#id2564419

@szahn
Copy link
Author

szahn commented Dec 8, 2012

Is there documentation on how to implement your own visitor pattern during implementation or intercept the event emitter such that you can define a style (flow or block) for a particular field in the object graph?

@szahn
Copy link
Author

szahn commented Dec 8, 2012

I was able to set the sequence style to flow only on primitive arrays by adding this code to the VisitSequenceStart() method in AnchorAssigningObjectGraphVisitor class. However, there should be a better way to do this, perhaps making it easier to pass in your own visitor when instantiating the serializer class.

if (sequenceType.IsArray && elementType.IsPrimitive)
{
info.Style = Core.Events.SequenceStyle.Flow;
}

@aaubry
Copy link
Owner

aaubry commented Dec 10, 2012

The Serializer class is meant to be a simple facade for the various classes that collaborate to the serialization process. However, it is still work in progress and that's the reason why it is not yet possible to alter the visitors that will be used, but this feature is definitely on top of the list. Your requirement of emitting arrays as flow sequences is the kind of usage that I had in mind when I started this refactoring.

@aaubry
Copy link
Owner

aaubry commented May 29, 2013

Now that version 2.0.0 is out, I think we should work on making the Serializer more extensible. I will keep you comments in mind while working on it. Thanks

@ghost ghost assigned aaubry May 29, 2013
@loudenvier
Copy link

Is flow style for sequences implemented in the current version? I was using YamlDotNet to dump objects but since I've got a few relatively large byte arrays it is making the dump next to unreadable (which defeats the purpose of Yaml :-) ) I was expecting something in SerializerOptions but didn't find anything, then stumbled on this issue. Any news?

@zeroregard
Copy link

zeroregard commented Feb 7, 2018

Is it there yet, or does anyone have some sort of hack/fix? Much appreciated.

@zeroregard
Copy link

zeroregard commented Feb 8, 2018

Anyone stumbling upon this, I was able to do it with this fork https://github.com/xoofx/SharpYaml

You then apply this attribute on the fields you want to have a different style:
[SharpYaml.Serialization.YamlStyle(YamlStyle.Flow)]

@samsmithnz
Copy link

@mathiassiig Is it possible to submit this as a pull request to the main branch? Especially with GitHub Actions YAML using this in places, it would be useful to have this functionality.

@EdwardCooke
Copy link
Collaborator

This issue appears to be abandoned, I'm going to close it. I believe this is already implemented.

@cmeeren
Copy link

cmeeren commented Aug 17, 2023

I can't see any information in this issue or linked issues that this is implemented. Is it, and if so, how can it be accomplished?

Also, is there any way to set max line length for flow-style arrays (making them break when the max length has been reached)?

@EdwardCooke
Copy link
Collaborator

We don’t have a way of doing that in yamldotnet that I’m aware of. We’re very grateful for pull requests if you want to create one.

@cmeeren
Copy link

cmeeren commented Aug 17, 2023

Thanks. Unfortunately swamped. I found a (hacky?) workaround: In Visit(YamlSequenceNode sequence), check the NodeType of the items of the sequence and check if they are YamlNodeType.Scalar.

In any case, it seems this issue was closed erroneously then. You may consider opening it, for clarity.

@EdwardCooke
Copy link
Collaborator

I closed because there was no comment for 3 years.

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

No branches or pull requests

7 participants