question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dump function not working with custom tag

See original GitHub issue

First 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:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
GeekyDeakscommented, Oct 18, 2019

Hi @hakimio - I noticed you are referring to load() and this issue is to do with the serialisation via dump() as the parsing is working - if your problem is actually related to load() 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 can

1reaction
GeekyDeakscommented, May 12, 2019
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found