Skip to content

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

Description

@goodrod

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions