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

Add format option to YamlMember to define Flow/Block serialization #311

Open
mdmoura opened this issue Mar 31, 2018 · 6 comments
Open

Add format option to YamlMember to define Flow/Block serialization #311

mdmoura opened this issue Mar 31, 2018 · 6 comments
Assignees

Comments

@mdmoura
Copy link

mdmoura commented Mar 31, 2018

I have the following class:

public class Post {
  public Int32 Id { get; set; }
  public String Title { get; set; }
  public List<String> Tags { get; set; }
  public List<Author> Authors { get; set; }
}

public class Author {
  public Int32 Id { get; set; }
  public String Name { get; set; }
}

When I serialize it I get:

id: 10
title: Using YAML
tags:
- Programming
- YAML
authors:
-id: 2
 name: Mary
-id: 8
 name: John

I would like the property tags to be serialized as flow like:

tags: [Programming,YAML]

More control on serialization format would be great because it will help people on editing them,

Maybe adding a new option to YAMLMember as follows:

[YamlMember(Format = Flow)]

Does this make sense?

@mdmoura mdmoura changed the title Add format option to YamlMember to include inline serialization Add format option to YamlMember to define Flow/Block serialization Mar 31, 2018
@aaubry
Copy link
Owner

aaubry commented Mar 31, 2018

I agree that this would be helpful to be able to set the SequenceStyle / MappingStyle. I just don't know what name to give to that property. It seems redundant to have two properties, one for sequences and the other for mappings. Maybe the name should be the opposite of "Scalar", such as "Structure" ? Since we already have the ScalarStyle property, we would have a StructureStyle property, accepting the same values as SequenceStyle / MappingStyle. What do you think?

@mdmoura
Copy link
Author

mdmoura commented Mar 31, 2018

Maybe an attribute named YamlStyle that would accept the enum with values Flow, Block or Any which would be the default value as in MappingStyle?

@aaubry
Copy link
Owner

aaubry commented Mar 31, 2018

I'd rather use the existing YamlMember attribute instead of adding a new one. Previously an effort was made to unify different attributes into a single one, and I don't think that we should deviate from this.

@ismael-moralesch
Copy link

Is this problem currently solved?

lqdchrm added a commit to lqdchrm/YamlDotNet that referenced this issue Dec 24, 2019
@lqdchrm
Copy link

lqdchrm commented Dec 24, 2019

I agree that this would be helpful to be able to set the SequenceStyle / MappingStyle. I just don't know what name to give to that property. It seems redundant to have two properties, one for sequences and the other for mappings. Maybe the name should be the opposite of "Scalar", such as "Structure" ? Since we already have the ScalarStyle property, we would have a StructureStyle property, accepting the same values as SequenceStyle / MappingStyle. What do you think?

i would like to use it like so:
[YamlMember(SequenceStyle = SequenceStyle.Flow)]
and
[YamlMember(MappingStyle = MappingStyle.Flow)]

Will try to impl...

@jtheisen
Copy link

Is there a more hacky way to somehow control this?

@EdwardCooke EdwardCooke self-assigned this Jan 15, 2023
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

6 participants