Skip to content
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

Problem with JSON serialization of rule result #47

Closed
serban-petrescu opened this issue Jul 1, 2017 · 3 comments
Closed

Problem with JSON serialization of rule result #47

serban-petrescu opened this issue Jul 1, 2017 · 3 comments

Comments

@serban-petrescu
Copy link

Summary:

I have an issue when serializing the rule result, namely the conditions inside this result.

Version

2.0.0

Example code

  let engine = new Engine();
  engine.addRule({
    "priority": 4,
    "event": {
      "type": "something"
    },
    "conditions": {
      "any": [{
        "fact": "data",
        "path": ".age",
        "operator": "lessThan",
        "value": 18
      }]
    }
  });
  engine.on("success", (event: any, almanac: any, result: any) => {
    console.log(JSON.stringify(result))
  })
  engine.run({
    data: {
      age: 16
    }
  });

The console will show:

{
	"conditions": "{\"priority\":1,\"any\":[\"{\\\"operator\\\":\\\"lessThan\\\",\\\"value\\\":18,\\\"fact\\\":\\\"data\\\",\\\"path\\\":\\\".age\\\"}\"]}",
	"event": {
		"type": "something"
	},
	"priority": 4,
	"result": true
}

If I look into the debugger it looks fine:
image

Cause

I did not really dig into this, but based solely on the debugger contents, I guess you "reused" the Condition class for the rule results (at least of the conditions inside it). The custom serialization of this class is most likely causing the issue. IMO, you should make a different "class" for the rule results (condition) object.

@CacheControl
Copy link
Owner

CacheControl commented Jul 2, 2017

Thanks for the detailed bug report @serban-petrescu

I have some time available this week and will get a fix put together.

@JonSilver
Copy link

JonSilver commented Jul 4, 2017

This is identical to the problem I've been having over in issue #42.

@CacheControl
Copy link
Owner

@serban-petrescu please re-open if 2.0.1 does not fix the issue.

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

No branches or pull requests

3 participants