-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
Comments
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? |
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) |
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. |
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 |
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? |
Is it there yet, or does anyone have some sort of hack/fix? Much appreciated. |
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: |
@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. |
This issue appears to be abandoned, I'm going to close it. I believe this is already implemented. |
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)? |
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. |
Thanks. Unfortunately swamped. I found a (hacky?) workaround: In In any case, it seems this issue was closed erroneously then. You may consider opening it, for clarity. |
I closed because there was no comment for 3 years. |
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
The text was updated successfully, but these errors were encountered: