node-js2xmlparser
node-js2xmlparser copied to clipboard
typeHandlers [object Boolean] doesn't work in 4.0.0
Hello,
Previously in 3.0.0, using a type handler for boolean field does correct things, it was transforming booleans into what you want. But it seems that, in some cases with 4.0.0, the booleans are stringified, so the type handler for them is not triggered.
Can you provide an example?
I'm going to close this for now, but if you provide an example I'll re-open the issue.
Long time after, here's a reproductible example in v4.0.2. The problem is located at https://github.com/michaelkourlas/node-js2xmlparser/blob/master/src/main.ts#L176 : stringify(value) is sometimes called too early, before typeHandlers are handled.
Description with examples:
const js2xmlparser = require('js2xmlparser');
const obj = {
tag: true
};
const options = {
typeHandlers: {
'[object Boolean]': bool => bool ? 'Y' : 'N'
}
};
console.log(js2xmlparser.parse('root', obj, options));
outputs as intended :
<?xml version='1.0'?>
<root>
<tag>Y</tag>
</root>
but
const js2xmlparser = require('js2xmlparser');
const obj = {
tag: {
'#': true
}
};
const options = {
typeHandlers: {
'[object Boolean]': bool => bool ? 'Y' : 'N'
}
};
console.log(js2xmlparser.parse('root', obj, options));
outputs, which is not intended :
<?xml version='1.0'?>
<root>
<tag>true</tag>
</root>
I suppose this bug occurs for any type of data, not only boolean.