0

I opened a ticket here but am hoping that somebody can answer fairly simply.

YamlDotNet doesn't support ISerializable, but Json.Net does. So, as a workaround we're trying to serialize our object to JObject first, which respects our serialization settings and only serializes the appropriate properties. Then, we want to send our JObject to the YamlSerializer, but we get this error:

"Object does not match target type"

Anthon
  • 69,918
  • 32
  • 186
  • 246
solvingJ
  • 1,321
  • 1
  • 19
  • 30
  • You might try recursively converting the `JObject` to a `Dictionary` first. The top-voted answer to [How do I use JSON.NET to deserialize into nested/recursive Dictionary and List?](https://stackoverflow.com/a/19140420/3744182) shows one way to do it. – dbc May 03 '17 at 19:04
  • Thanks for the suggestion. Converting to JObject is painful enough, but then to convert that to something else again, just to maybe get it into YAML seems... untenable. – solvingJ May 03 '17 at 19:20

1 Answers1

0

Suggestion as per following post can be used as workaround: How to convert JSON to YAML using YamlDotNet

i.e. convert JSON to YAML using dynamic Expando object.

Example:

var expConverter = new ExpandoObjectConverter();
var jsonString = JsonConvert.SerializeObject(anyObject);
var expandoObject = JsonConvert.DeserializeObject<ExpandoObject>(jsonString, expConverter);
var textInYamlFormat = serializer.Serialize(expandoObject);
olydis
  • 3,192
  • 13
  • 28