Questions tagged [yamldotnet]
YamlDotNet is a .NET library for YAML
189
questions
3
votes
0
answers
52
views
YAML C# Add new line between items
I'm looking for a way of adding new line per every new line (as I show below: "before" and "after")
var yamlSerializer = new SerializerBuilder()
.AddNewLinePerEveryNewItem() // ...
0
votes
0
answers
36
views
How to add a mapping node to a YAML file without affecting comments
I have below yaml file
Input:
# Emp1 details
Employee1: &dept
DeptCode: ABC
Tower: T1
I want to add below yaml content with mapping key
# Emp2 details
Employee2: &IT
<<: *dept
...
0
votes
0
answers
47
views
How to deserialize YAML objects into C# classes based on key name
I'm trying to use YamlDotNet to deserialize an array of objects into C# classes based on the key of those objects.
I have YAML like this:
steps:
- launch:
name: application
- click:
...
0
votes
1
answer
87
views
Can't deserialize list with anchor YamlDotNet
I think this might be a problem with YamlDotNet but that does seem somewhat unlikely given that it's quite a well used library so figured I'd ask.
I have this bit of yaml:
Methods:
- Name: "...
0
votes
0
answers
26
views
How to have the `INamingConvention` passed into a custom value converter?
I wrote a custom value converter for YamlDotNet. I initialize it like this:
var ser = new SerializerBuilder().WithNamingConvention(UnderscoredNamingConvention.Instance).WithTypeConverter(...
0
votes
1
answer
131
views
Jschema Validation not validating Array Objects when they are declared using $ref in the schema
JSON Schema validation is not validating Array items when items are declared using $ref in the Schema. It allows additional properties in the object which are not present in the schema although ...
0
votes
0
answers
76
views
How to set meaningful names for anchor tags during Yaml serialization using YamlDotNet library in C#?
Set anchor tag name during serialization using YamlDotNet library.
I am using YAMLDotNet to serialize object to Yaml.
I am using XML file and generating YAML out of it using YamlDotNet. The YAML that ...
0
votes
1
answer
84
views
YamlDotNet doesn't support deserializing KeyValuePair<,> types
I've got a scenario in which I need to deserialize a sequence of maps to IEnumerable<KeyValuePair<string, string>> that wouldn't be solved by simply using Dictionary<string, string> ...
1
vote
2
answers
393
views
c# yamldotnet deserialize scalar or sequence in yaml dynamically
I am using YamlDotNet library, and I wanted to deserialize the 1000s of Yaml file using a common data structure class.
Sample class have given below. The class Jobs contains a filed Pool which can be ...
0
votes
1
answer
287
views
YamlDotNet apparently does not use NamingConvention during deserialization
I'm sure I'm getting things wrong, since it is widely used, but this test fails for me:
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
class Test
{
...
0
votes
0
answers
39
views
YamlDotNet: Deserialize tag mapped values using parameterless constructor
YamlDotNet seems to deserialize an array of tag mapped values as nulls instead of using the default construction for each class. Is there any possibility to create instances using the default ...
0
votes
0
answers
75
views
How to deserialize unknown members with YamlDotNet
This code does not work because
YamlDotNet.Core.YamlException: 'Property 'unknown1' not found.
How do I configure this correctly (if it is possible at all)
using System.Runtime.Serialization;
using ...
0
votes
0
answers
68
views
YamlScalarNode distinguish between Key and Value
I want to use YamlDotNet to go through all keys (but not their values) of a YAML document and check the key for a pattern. My code looks like this:
foreach (var node in yaml.Documents.Single()....
0
votes
0
answers
135
views
YamlDotNet how to deserialize a string with a new line
I'm trying to deserialize a string with new line separators in it. This post suggested using > or |, but when I add these in my yml file I get the following error:
While scanning a block scalar, ...
0
votes
0
answers
170
views
how to serialize dynamic json object with yamldotnet
i'm trying to creating yaml file from json using with YamlDotNet library, but i need to use dynamic object because i don't know what type of object they will send me,
I created base class for ...
-2
votes
1
answer
123
views
Serializing a List<KeyValuePair<string, string>> not working properly
I have a yaml file that looks like this:
pcap:
- interface: eth0
- interface: default
I would like, through my ASP.NET (C#) program, to add to this section, more lines according to what the user ...
0
votes
1
answer
286
views
How to make space indentation and blank row space in yaml file with c#
I'm new in using yaml files, and after searched in the web I didn't found a solution yet.
I generate a yaml files and I want to make some indentations like this examples:
My currrent output:
fields:
...
3
votes
1
answer
433
views
Why can I not deserialize YAML into a record?
I am using YamlDotNet and I wanted to use records for my deserialized YAML. However, I get an error like this when I try to do so:
Unhandled exception. (Line: 2, Col: 3, Idx: 9) - (Line: 2, Col: 3, ...
0
votes
1
answer
81
views
yamldotnet added 0x0d in desktop application but not in xamarin android
I need help for my code, i will try to generate license file in cross-platform with yamldotnet but output different then desktop, it's removed 0x0D in xamarin android, i need to keep it 0x0D.
Code for ...
2
votes
1
answer
844
views
YamlDotNet: How do I deserialize either a Sequence or a Mapping?
There's a YAML configuration file that my application loads:
sonarr:
- base_url: abc1
api_key: xyz1
- base_url: abc2
api_key: xyz2
I want to change the schema for this to use a mapping (for named ...
0
votes
0
answers
131
views
How to serialize / deserialize deeply nested nodes with YamlDotNet?
I'm trying to create / read a MongoDB configuration file through C#.
The format is YAML and some nodes are deeply nested like this:
storage.wiredTiger.engineConfig.cacheSizeGB : 5
From the getting ...
0
votes
1
answer
170
views
Hide specific root object during yaml serialization and show only it's children properties in yaml
I am using one object model
public class MainModel
{
public FirstChildModel firstChild { get; set; }
public SecondChildModel secondChild { get; set; }
}
public class FirstChildModel
{
public string ...
1
vote
2
answers
210
views
How do I specify the date locale when Dserializing YAML using YamlDotNet?
In a YAML document, I've got a date formatted using an EN-GB locale (so 07/02/2019 is 2nd February 2019)
When I deserialize the document using YamlDotNet, it interprets this as an EN-US date so it ...
3
votes
1
answer
187
views
Can YamlDotNet's IDeserializer be used as a singleton in IServiceCollection?
I'm configuring a YamlDotNet deserializer like this:
static IDeserializer CreateYamlDeserializer()
{
var deserializer = new DeserializerBuilder()
.WithNamingConvention(...
3
votes
0
answers
204
views
How do I create recursive custom tags in YAMLDotNet
I'm working with YAML in C#, using YamlDotNet. I've created a custom tag that will deserialize to a simple object supporting string interpolation. Let's say the tag is "!StrInterp", and ...
1
vote
1
answer
998
views
How can I apply YamlDotNet ScalarStyle.SingleQuoted to the string property within a List<string>?
I'm using YamlDotNet to serialize an object like this
using System.Collections.Generic;
using YamlDotNet.Core;
using YamlDotNet.Serialization;
public class Thing
{
[YamlMember(ScalarStyle = ...
2
votes
2
answers
1k
views
YamlDotNet Convert YAML to JSON in C#
I need help when trying to convert a yaml to json it is passing all the properties to string, and it does not recognize the bool or integer fields.
I am using the YamlDotNet library, in c #. If anyone ...
0
votes
1
answer
513
views
How to signal YamlDotNet to serialize byte[] as !!binary type in .NET 5 (previous answer is not working)
In question YamlDotNet !!binary type the answer provided by Antoine Aubry and the example in A fully working example can be tried here do not work with Version="11.2.1".
Is there any way to ...
2
votes
1
answer
1k
views
How to update a property value in YamlDotNet?
I'm trying to load an existing yaml file and update some of its properties.
However- I'm trying not to override the other properties.
My yaml:
A:
a1: value1
a2: value2
Desired yaml:
A:
a1: ...
2
votes
1
answer
2k
views
How to deserialize YAML property into a class with passed parameters?
I'm trying to achieve a functionality implemented in the game "RimWorld" with XML, using YamlDotNet.
I am aware of how to deserialize basic information, like so: instanceOfDeserializer....
0
votes
1
answer
664
views
Remove specific field of yaml file using YamlDotNet
I'm developing an application which reads a yaml file. Let's say the yaml file has the following content:
field1: 'test1'
field2: 'test2'
field3: 'test3'
So I want to remove only the filed2 as so the ...
0
votes
1
answer
247
views
Nested string to class deserialization using YamlDotNet
I need to be able to dynamically deserialize strings (as properties) into classes during runtime. I also need to be able to do this in a way that supports nesting.
Example - Turret which shoots ...
2
votes
1
answer
771
views
How to convert YAML data to a HTML table using YAMLDONET and C#?
I need to read a YAML file and then convert it to HTML file.
I tried using YAMLDOTNET and C#.
This is an example of the YAML file;
component1:
kbName : KB210006
grayVersion ...
1
vote
1
answer
547
views
Can YamlDotNet Deserialize to an dynamic object graph?
I have a large YAML document that I want to deserialize to a dynamic object (ExpandoObject). Can YamlDotNet deserialize directly to a dynamic object tree?
I can get there by going to Json first and ...
0
votes
0
answers
69
views
Security implications of deserializing arbitray objects from YAML with yamldotnet
I'm currently evaluating this library from a security perspective. Since YAML can be used to serialize objects, I was wondering if the defaults provided by the parser are set such that deserialization ...
0
votes
0
answers
483
views
YamlDotNet: Deserialize object to string with line separator between each object
I'm using the following code to deserialize and serialize my object
var deserializer = new DeserializerBuilder().WithTagMapping("str", typeof(string)).Build();
var baseObject = deserializer....
0
votes
1
answer
301
views
How to only serialize a special property's value to json
YamlDotNet can deserialize a yaml document which contain json.
Suppose there is a yaml document as input like below.
fieldA: a
fieldB:
- { "subFieldA": "a1","subFieldB":...
3
votes
2
answers
2k
views
How do I parse only part of YAML using YamlDotNet?
Suppose I have the following YAML:
config_one:
name: foo
stuff: value
config_two:
name: bar
random: value
I want to selectively parse config_one into an object and I want config_two to be ...
1
vote
1
answer
281
views
How to handle cycles in object graph with yamldotnet serializers
I'm trying to use Yamldotnet library to serialize a model with circular references. Which serializer settings or data class attributes should I use to achieve this? I want to be able to serialize and ...
0
votes
1
answer
907
views
Getting dynamic list entries from a YAML
My input YAML looks like
menu:
- 'key one': 'first'
- 'key two': 'second'
so quite simple. The sub-keys for menu are arbitrary values so there can be anykey:anyvalue.
Now I'm using YamlReader to ...
0
votes
1
answer
657
views
c# usage of list in yaml - error in serialization
I'am able to deserialize the yaml file, consult and change the values.
Due to an requirement, I have to use the minus(-) symbol in front of the variables NAME, VERSION, ...
The file test.yaml
PlatForm:...
2
votes
1
answer
1k
views
Exception when deserializing yaml file to property of abstract class using YamlDotNet
Using YamlDotNet, I'm trying to deserialize a yaml file with a nested object graph into a set of custom .net types. This works if I set the tree property to a simple PopulationBasicNode, but when I ...
1
vote
1
answer
4k
views
Error deserializing yaml with yamldotnet - Property not found
I'm using C#, YamlDotNet and following the example:
How to deserialize YAML with YAMLDotNet?
But I'm getting the follow error:
Exception thrown: 'YamlDotNet.Core.YamlException' in YamlDotNet.dll
...
0
votes
1
answer
1k
views
YamlDotNet change property name according to value
I am trying to format the name of property of an object according to value I am getting in the output of my yaml file. I am using yamldotnet library. Below are my classes
State.cs
public class State
...
-1
votes
1
answer
426
views
Need help in deserializing unity asset bundle manifest file
I need to deserialize main Unity asset bundle manifest in order to merge them later (all in one).
How do you approach something like this :
ManifestFileVersion: 0
CRC: 4271548926
AssetBundleManifest:
...
1
vote
1
answer
179
views
How to serialize a YamlNode graph?
YamlDotNet seems to support serializing POC graphs, but I can't find an API that serializes an object graph made directly of YamlNode types. Is there a way to do this?
0
votes
1
answer
217
views
How do you deserialize static properties with YamlDotNet?
I'm having trouble deserializing yaml into static properties. When I try, I get the exception System.Runtime.Serialization.SerializationException: Property 'Test' not found on type 'Program+Config'. ...
6
votes
1
answer
6k
views
YamlDotNet - Custom Serialization
I have a .NET class which represents a RPC method call, like this:
class MethodCall
{
public string MethodName { get; set; }
public Collection<object> Arguments { get; set; }
}
I want ...
4
votes
0
answers
2k
views
How to preserve the comments when parsing yaml stream in C#?
I am using YamlDotNet for reading and writing yamls. The content of the yaml file is first loaded into YamlStream and the document is processed and modified. After the document is processed, the ...
1
vote
1
answer
247
views
Why isn't content written to yaml document?
My intention is to write an array of Items in a yaml file, format should be like this:
- country: Denmark
city: Copenhagen
- country: Italy
city: Rome
So I wrote this method:
public static void ...