Dump function not working with custom tag
See original GitHub issueFirst thanks for the great library!
I’m trying to build a YAML-JSON tool but got some trouble on the JSON->YAML part. Following the example, I build the custom type like below:
function ACustomTag(value) {
this.klass = 'ACustomTag';
this.value = value;
}
const customtagYamlType = new yaml.Type('!ACustomTag', {
kind: 'scalar',
resolve: data => !!data && typeof data === 'string' && data.trim(),
construct: data => new ACustomTag(data),
instanceOf: ACustomTag,
represent: customTag => customTag.value
});
The JSON->YAML part works great, it translates my yaml file, which contains a !ACustomTag to the correct JSON object like
key: {
klass: ACustomTag,
value: 1
}
But when I try to use this result to serialize it back to YAML, this part is not recognized as a ACustomTag class instance. And the yaml result is like
key:
klass: ACustomTag,
value: 1
Instead of expection:
key: !AcustomTag 1
Is it some configuration part that I need to set to allow it converting custom tag back to YAML?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
python - PyYAML: load and dump yaml file and preserve tags ...
I have been working on a fix for this in my ruamel.yaml package as the ... CustomTag: that ends in a colon, but...
Read more >Getting "Internal Server Error: Function 'dump' does not exist ...
As part of my troubleshooting process, I dumped the database on the staging site and imported my local version. I also replaced the...
Read more >How to Serialize a Class Object to JSON in Python
Method 5: Implement a custom to_json() method. To solve the double-quotation mark problem, you need to implement a custom to_json() method in the...
Read more >The Yaml Component (Symfony Docs)
Whenever you have a syntax problem with your YAML files, the library outputs a helpful ... The dump() method dumps any PHP array...
Read more >django-admin and manage.py
Prints the SQL that would be run without actually running it, ... dumping records which might otherwise be filtered or modified by a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @hakimio - I noticed you are referring to
load()
and this issue is to do with the serialisation viadump()
as the parsing is working - if your problem is actually related toload()
can you start another issue and also include some code and YAML to show what you are doing and how you are using the schema? I’m not a maintainer btw, just a user of the module, but I’ll try and help if I canI tried your code snippet and it worked for me. Did you set the
schema
during the call todump()
?https://github.com/nodeca/js-yaml/blob/665aadda42349dcae869f12040d9b10ef18d12da/lib/js-yaml/dumper.js#L810-L813
You can see the options here:
https://github.com/nodeca/js-yaml/blob/665aadda42349dcae869f12040d9b10ef18d12da/lib/js-yaml/dumper.js#L107-L118