Skip to content

RuleResult does not serialize #172

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

Closed
silesky opened this issue Nov 25, 2019 · 1 comment
Closed

RuleResult does not serialize #172

silesky opened this issue Nov 25, 2019 · 1 comment
Labels

Comments

@silesky
Copy link

silesky commented Nov 25, 2019

Related to: #47

I get the following response when attempting to to serialize a RuleResult (i.e. using express's res.json(ruleResult) method).

"{\"conditions\":{\"priority\":1,\"all\":[{\"priority\":1,\"any\":[{\"priority\":1,\"any\":[{\"operator\":\"in\",\"value\":[\"foo\",\"bar\",\"baz\"],\"fact\":\"productType\",\"factResult\":\"baz\",\"result\":true}...

As a workaround, I've done JSON.parse(JSON.stringify(ruleResult));

can we either:

  • have them serialize properly
  • add a .toJSON() method?
@silesky silesky changed the title RuleResult does not serialize properly RuleResult does not serialize Nov 25, 2019
@CacheControl
Copy link
Owner

I'm unable to reproduce this problem - perhaps this is no longer a problem due to rule-result now having a toJSON() method defined?

const stringified = JSON.stringify(ruleResult)
console.log(stringified)
// no double escaping:
// {"conditions":{"priority":1,"any":[{"operator":"greaterThanInclusive","value":21,"fact":"age","factResult":21,"result":true},{"operator":"equal","value":true,"fact":"qualified","factResult":false,"result":false}]},"event":{"type":"setDrinkingFlag","params":{"canOrderDrinks":true}},"priority":100,"result":true}

I checked the express source code and they're not doing anything fancy - just JSON.stringify()

If anyone still has this problem please comment and we'll re-open. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants