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.

`ActionContext.GetContext<string>("property")` returns json token of `{{ ValueKind: 3}}` instead of actual value.

See original GitHub issue

Hi,

I’m using 3.2.0.

I have a custom action in a action trigger:

 public class PropertySetterAction : ActionBase
    {
        private readonly RuleExpressionParser _expressionParser;

        public PropertySetterAction(RuleExpressionParser expressionParser, object input)
        {
            _expressionParser = expressionParser;
        }
        public override ValueTask<object> Run(ActionContext context, RuleParameter[] ruleParameters)
        {
            
            var propertyName = context.GetContext<string>("propertyName");
            var value = context.GetContext<string>("newValue");
            
            return new ValueTask<object>(this._expressionParser.Evaluate<object>(value, ruleParameters));
        }
    }

Debugger view: image

My Rules look like this:

[
  {
    "WorkflowName": "Employee Validations",
    "Rules": [
      {
        "RuleName": "If Employee Last name is unset, use first name as last name",
        "Expression": "!string.IsNullOrWhiteSpace(input1.LastName)",
        "Actions": {
          "OnFailure": {
            "Name": "PropertySetterAction",
            "Context": {
              "propertyName": "LastName",
              "newValue": "input1.FirstName"
             }
          }
        }
      }
    ]
  }
]

My expectation is that propertyName in context would be the literal LastName and the value of newValue would be evaluated to an expression.

Am I missing something or is there a defect?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
abbasc52commented, Jul 16, 2021

@ElanHasson I digged deeper into the issue and realized that System.Text.Json does not play well with Object type and generates valuekind like object. https://josef.codes/custom-dictionary-string-object-jsonconverter-for-system-text-json/

It looks like something beyond the scope of this library, and we would recommend using Newtonsoft (or pass the json as string) till we are able to fully migrate to System.Text.Json

I will be closing this issue for now and will include this as a part of documentation

1reaction
ElanHassoncommented, Jul 2, 2021

@abbasc52, what is the work necessary to support? I can send a PR.

Any interest in supporting whatever serializer via configurable extensibility points in ReSettings?

Read more comments on GitHub >

github_iconTop Results From Across the Web

dynamic c# ValueKind = Object - asp.net core
Json which introduce new JsonElement ValueKind so ValueKind is from System.Text.Json library and JsonConvert is from Newtonsoft library.
Read more >
.Net 6 - Rest Api is deserializing property of "object" type to ...
When I first tried saving the data, it wrote {"ValueKind": 4} to the database instead of raw value I was expecting. Throwing errors...
Read more >
How to use a JSON DOM in System.Text.Json
Create a DOM from a JSON string; Write JSON from a DOM. Get a value, object, or array from a DOM. C#
Read more >
JsonElement.ValueKind Property (System.Text.Json)
Gets the type of the current JSON value.
Read more >
Deserialization with System.Text.Json - Marc Roussy
An overview of the many ways of deserializing JSON with System. ... each JSON token all the while keeping memory usage down to...
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