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

JToken.ToObject<T>() not working in expressions #327

Open
goodrod opened this issue Nov 12, 2024 · 1 comment
Open

JToken.ToObject<T>() not working in expressions #327

goodrod opened this issue Nov 12, 2024 · 1 comment

Comments

@goodrod
Copy link

goodrod commented Nov 12, 2024

Dynamic expression version

Problematic code

        var interpreter = new Interpreter();
        var test = JObject.Parse("{ \"date\": \"2024-11-11T11:11:11Z\" }");
        interpreter.SetVariable("test", test);
        var result = interpreter.Eval("test.SelectToken(\"$.date\").ToObject<DateTime>()");

Actual behavior
The following exception:

DynamicExpresso.Exceptions.ParseException : '.' or '(' expected (at index 44).
   at DynamicExpresso.Parsing.Parser.ValidateToken(TokenId t, String errorMessage)
   at DynamicExpresso.Parsing.Parser.ParseTypeKeyword(Type type)
   at DynamicExpresso.Parsing.Parser.ParseIdentifier()
   at DynamicExpresso.Parsing.Parser.ParsePrimaryStart()
   at DynamicExpresso.Parsing.Parser.ParsePrimary()
   at DynamicExpresso.Parsing.Parser.ParseUnary()
   at DynamicExpresso.Parsing.Parser.ParseMultiplicative()
   at DynamicExpresso.Parsing.Parser.ParseAdditive()
   at DynamicExpresso.Parsing.Parser.ParseShift()
   at DynamicExpresso.Parsing.Parser.ParseComparison()
   at DynamicExpresso.Parsing.Parser.ParseLogicalAnd()
   at DynamicExpresso.Parsing.Parser.ParseLogicalXor()
   at DynamicExpresso.Parsing.Parser.ParseLogicalOr()
   at DynamicExpresso.Parsing.Parser.ParseConditionalAnd()
   at DynamicExpresso.Parsing.Parser.ParseConditionalOr()
   at DynamicExpresso.Parsing.Parser.ParseConditional()
   at DynamicExpresso.Parsing.Parser.ParseAssignment()
   at DynamicExpresso.Parsing.Parser.ParseExpressionSegment()
   at DynamicExpresso.Parsing.Parser.ParseExpressionSegment(Type returnType)
   at DynamicExpresso.Parsing.Parser.Parse()
   at DynamicExpresso.Parsing.Parser.Parse(ParserArguments arguments)
   at DynamicExpresso.Interpreter.ParseAsLambda(String expressionText, Type expressionType, Parameter[] parameters)
   at DynamicExpresso.Interpreter.Parse(String expressionText, Type expressionType, Parameter[] parameters)
   at DynamicExpresso.Interpreter.Eval(String expressionText, Type expressionType, Parameter[] parameters)
   at DynamicExpresso.Interpreter.Eval(String expressionText, Parameter[] parameters)

Expected behavior
To return a DateTime parsed from the json.

@davideicardi
Copy link
Member

Yes, unfortunately this is a know limitation, see https://github.com/dynamicexpresso/DynamicExpresso?tab=readme-ov-file#limitations
As usual any help is appreciated.

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

No branches or pull requests

2 participants