Skip to content

add_multi_constructor equivalent / unknown tag handler #385

Closed
@akdor1154

Description

@akdor1154

In PyYAML, I can use the add_multi_constructor feature to allow me to define a constructor for multiple tags. I am using it to handle any unknown tags. For example, I could use this to deserialize the document

thing1: !someTag asdf
thing2: !someOtherTag fdsa

into the JS structure

{
  thing1: UnknownTag { tag: 'someTag', value: 'asdf' },
  thing2: UnknownTag { tag: 'someOtherTag', value: 'fdsa' }
}

and be able to re-serialize that structure back into equivalent yaml.

My use case is to read and modify a tiny part of a big yaml file that has a bunch of domain-specific tags in it. I don't care how the tags are resolved as I'm not reading that part of the file, but currently with js-yaml I can't read it at all because to parse the file in the first place results in an unknown tag error. Even if I set it to skip unknown tags, I can't re-serialize the modified docjument.

This is fine with PyYAML as I can use add_multi_constructor as defined above to handle any unknown tags, but as far as I can tell this behvaiour is impossible to achieve with js-yaml.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions