Skip to content

[Question] Is there a way to output a string property using the multi-line block scalar styles (>, |)  #20

Closed

Description

@dfkeenan

Hi,

Subject pretty much covers it. I am trying to serialize a class with string properties and want to out put them in the block style without quotes and "\r" or "\n".

I have been trying to do it with the SerializerSettings like:

            var ocrTemplateType = typeof(OcrTemplate);
            settings.RegisterTagMapping("!OcrTemplate", ocrTemplateType);
            settings.Attributes.Register(ocrTemplateType.GetProperty(nameof(OcrTemplate.Text)), new YamlMemberAttribute(0));
            settings.Attributes.Register(ocrTemplateType.GetProperty(nameof(OcrTemplate.Text)), new YamlStyleAttribute(SharpYaml.YamlStyle.Block));

Cheers,
dfkeenan

Activity

  1. jakob-nielsen-dfds commented on Dec 13, 2018

    @jakob-nielsen-dfds

    Any news on this?

    I experience the same when trying to save a stream to a file.
    I have a multi-line block scalar in my input file, and would like to keep the formatting on the output file.

  2. xoofx commented on Dec 13, 2018

    @xoofx
    Owner

    I don't have any spare time dedicated to this project, so digging into the problem and PR are welcome

  3. baywet commented on Oct 24, 2025

    @baywet
    Contributor

    I put together #124 to address this.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions