Comments (4)
I am looking for answer to this thread. I am using XML file and generating YAML out of it using YamlDotNet. The YAML that gets generated has anchor tags but the name of the tags is not meaningfully. I want to control the name given to anchor tag and give a more meaningful name to it. Is there any easy way to do it or will have to write a custom emitter for it.
from yamldotnet.
I think you can replace this implementation with your own and be able to create more meaningful names. However, you may not be able to get meaningful context to generate a name that makes sense.
from yamldotnet.
Since there was a solution provided with no feedback Iām closing this issue. If you disagree go ahead and reopen it and we can discuss more.
from yamldotnet.
Since there was a solution provided with no feedback Iām closing this issue. If you disagree go ahead and reopen it and we can discuss more.
@EdwardCooke - I think this is reasonable, but am having trouble getting the IAliasProvider implementation to trigger. I mostly copied the AnchorAssigner, but customized the name portion. I then provided this to my serializer like this:
var anchorNaming = new CustomAnchorAssigner(new List<IYamlTypeConverter>()
{
customConverter1,
customConverter2,
customConverter3,
});
var serializerBuilder = new SerializerBuilder()
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitEmptyCollections)
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull)
.WithTypeConverter(customConverter1)
.WithTypeConverter(customConverter2)
.WithTypeConverter(customConverter3)
.WithPreProcessingPhaseObjectGraphVisitor(anchorNaming)
This triggers all of the VisitObject
events, but the GetAlias
method is never called. Is there something I'm missing to use this Alias Provider?
Edit:
I was able to get this working by adding the following line to the SerializerBuilder
.WithEmissionPhaseObjectGraphVisitor(args => new AnchorAssigningObjectGraphVisitor(args.InnerVisitor, args.EventEmitter, anchorNaming),
w => w.InsteadOf<AnchorAssigningObjectGraphVisitor>())
from yamldotnet.
Related Issues (20)
- `YamlStream.Load(TextReader)` interprets an empty value as an empty string instead of null. HOT 2
- Emitter doesn't handle comments between the mapping value and key HOT 1
- An exception occurs during Deserialize DateTimeOffset HOT 4
- How to have the `INamingConvention` passed into a custom value converter? HOT 3
- Parser does not recognize quoted keys HOT 2
- Can't handle anchored lists HOT 11
- Cannot parse YAML file, (Line: 2, Col: 3, Idx: 6) - (Line: 2, Col: 3, Idx: 6): Exception during deserialization HOT 2
- Do you think it's useful to add some F# examples along with the C# code? HOT 4
- Schema validation support HOT 10
- Unwanted conversion from a string to a numeric value HOT 1
- missing `IDeserializer object? Deserialize(string input)` method HOT 2
- How to Serialize an object with Directives, start and end marks (---, ...)? HOT 2
- How to forcefully interpret as an array with implied key HOT 3
- YamlStream.Load with JSON with emojis (even escaped) fails: "While scanning a quoted scalar, found invalid Unicode character escape code." HOT 13
- OmitDefaults doesn't work for properties of sub-objects HOT 14
- Polymorphic deserialization - Alias $example_word cannot precede anchor declaration HOT 4
- DateTime fails Serialization/Deserialization roundtrip when JsonCompatible is on HOT 5
- Serialization/Deserialization vs strings with funny characters HOT 8
- How do I use this with multiple documents of arbitrary types? HOT 3
- YamlMember Alias usage HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yamldotnet.