-
-
Notifications
You must be signed in to change notification settings - Fork 172
Support serialization of strings to literal and folded scalars #174
Comments
I'm also interested in this feature, and several others, but this would have to be implemented by the underlying library used by serde-yaml. Currently, that is yaml-rust, which is not really maintained. There are three unanswered pull requests for yaml-rust to add the feature:
There isn't much that can be done from serde-yaml I'm afraid. |
I see... I was worried that that was the case 😞 Hopefully when those PRs are addressed or a fork is created, this issue can be addressed. Thanks for your answer! |
@dtolnay Is this something that you would want in this library? Or should I use my own fork(s) if I want this? The main problem does lay at https://github.com/chyh1990/yaml-rust I guess? |
To the extent that this issue is asking to expose choice over the string representation at the granularity of individual fields, that is not something I would accept in this library. If it is asking just for prettier defaults, such as serializing to literal scalar if a string value contains newlines, I am open to that but this crate is not where that code lives. |
@dtolnay |
I wouldn't do that. It would be good to drop the dependency on yaml-rust entirely though, in favor of the backend style described in dtolnay/request-for-implementation#9. |
That is actually what I initially wanted, but was worried that it was too opinionated 😆
If/when possible, could this issue be transferred to the relevant repo? |
Apologies if this feature already exists, but I didn't see it in the documentation.
Info
the literal scalar
|
can be used in YAML to break up a string to multiple lines, treating the line breaks literally.the folded scalar
>
also can be used to break up a string into multiple lines, but it treats line breaks as spaces.Request
When serializing a value containing a multiline string, it seems to always serialize that string to a single line with line breaks represented as
\n
(reproduction)I think that there should be some way to specify how you want your string to be serialized (single line, folded scalar, literal scalar).
Scalar Examples
Literal:
|
Input
Output (JSON)
Folded:
>
Input
Output (JSON)
The text was updated successfully, but these errors were encountered: