0

I would like to parse the following YAML

urls:
   who: /fr-fr/who-we-are
   test: /fr-fr/test

targetDirectory: d:\temp

Into the following structure:

public class UserConfig 
{ 
    public Dictionary<string, string> Urls { get; set; } 
    public string TargetDirectory { get; set; } 
}

I try to serialize it with:

var deserializer = new DeserializerBuilder() 
                      .WithNamingConvention(new CamelCaseNamingConvention())
                      .Build();

But I always obtains the following error: (Line: 2, Col: 1, Idx: 8) - (Line: 2, Col: 2, Idx: 9): Expected 'MappingStart', got 'SequenceStart' (at Line: 2, Col: 1, Idx: 8).

Is this library able to support a mapping of key values? If yes how can I do that?

EDIT:

This YAML give me the exact same result:

urls: 
- who: /fr-fr/qui-sommes-nous?sc_site=schmidttest
- fabricantfrancais: /fr-fr/avantages-cuisinella/1er-fabricant-francais

targetDirectory: d:\temp

Regards, Benjamin V.

Kapoue
  • 847
  • 2
  • 11
  • 15
  • Are you sure you parse the correct YAML? The error message suggests there is a sequence in your YAML at line 2, while there evidently is none in your YAML. – flyx Jun 21 '18 at 08:58
  • Yes I have tried with this syntax but also with the other one I have added in the message and the message is the same. – Kapoue Jun 21 '18 at 09:11

1 Answers1

1

Hello I have received an answer from the github manager: https://github.com/aaubry/YamlDotNet/issues/328

That's because your YAML document is a sequence of mappings, instead of a mapping. That would map to a List>. If you can control the structure of your YAML document, you should change it to:

urls: who: /fr-fr/who-we-are test: /fr-fr/test

targetDirectory: d:\temp\ otherwise, you will need to implement a class that implements ICollection and use that type as the Urls property.

Thank you for your help!

Kapoue
  • 847
  • 2
  • 11
  • 15