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 anchor/alias support in JsonEventEmitter #490

Merged
merged 1 commit into from May 28, 2020

Conversation

am11
Copy link
Contributor

@am11 am11 commented May 9, 2020

Today, serializing the following YAML with .JsonCompatible() throws Unhandled exception. System.NotSupportedException: Aliases are not supported in JSON:

x: &anchor1
  z:
    v: 1
y:
  k: *anchor1

This PR adds support for anchors and aliases, such that it produces JSON replicating the anchored value:

{
   "x": {
      "z": {
         "v": "1"
      }
   },
   "y": {
      "k": {
         "z": {
            "v": "1"
         }
      }
   }
}

It makes it very close to other frameworks, e.g. https://www.convertjson.com/yaml-to-json.htm (modulo quoted numeric value "1" in our case when deserializing-then-reserilizing a dynamic object vs. unquoted 1 in theirs).

Also:

  • fix a warning Serialization\SerializerBuilder.cs(557,64): warning CS8625: Cannot convert null literal to non-nullable reference type.
  • rename YamlDotNet/Serialization/YamlMember.cs to match class name: YamlDotNet/Serialization/YamlMemberAttribute.cs.
  • add missing copyright header in YamlDotNet/Core/EmitterSettings.cs.

@am11 am11 force-pushed the feature/emitter/json-with-anchors branch from 269e2db to 536d341 Compare May 9, 2020 10:02
@am11 am11 changed the title Add anchor/alias support in JsonEmitter Add anchor/alias support in JsonEventEmitter May 9, 2020
@am11 am11 force-pushed the feature/emitter/json-with-anchors branch 5 times, most recently from 5dfcc49 to cd23936 Compare May 10, 2020 20:21
@am11 am11 force-pushed the feature/emitter/json-with-anchors branch from cd23936 to b22f5ba Compare May 10, 2020 20:41
@aaubry aaubry merged commit 3691664 into aaubry:master May 28, 2020
@am11 am11 deleted the feature/emitter/json-with-anchors branch May 28, 2020 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants