Unable to evaluate string with "-"
See original GitHub issueUsecase - I’m trying to do nested lookup in Map. Issue - If the “.” separated key I’m searching in the map has “-”, then evaluation fails
public void test() {
Map attribute = new HashMap<String, Object>() {{
put("merchant_attributes", new HashMap<String, Object>() {{
put("c652a326-5243-12ab-a4cd-111111", new HashMap<String, Integer>() {{
put("num_orders", 2);
}});
}});
}};
MVEL.eval("merchant_attributes.c652a326-5243-12ab-a4cd-111111.num_orders", attribute);
}
Evaluating the above test throws an error saying [Error: could not access: c652a126; in class:
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
I am unable to evaluate string using eval() - Stack Overflow
I am trying to make a calculator application.I want to evaluate the contents of a TextView and display it as a toast message....
Read more >Debugger unable to evaluate string interpolation
When trying to use the watch, immediate window or any other option for evaluating expressions when debugging, VS2022 is unable to evaluate simple...
Read more >Unable to eval expression when debugging #2485 - GitHub
Unable to eval expression when debugging #2485 ... package main import ( "fmt" "strings" ) func WordCount(s string) map[string]int { m ...
Read more >Unable to evaluate expression because the code is ... - MSDN
I have some code that gets the exception Unable to evaluate expression because the code is optimized or a native frame is on...
Read more >eval() - JavaScript - MDN Web Docs - Mozilla
The eval() function evaluates JavaScript code represented as a string and ... during evaluation of the code, including SyntaxError if script fails to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I tried it and it evaluates to a singleton map with num_order=2 your test was ignoring the result but I changed the last line to:
When using strings as keys using the square brackets operator, the leading numbers do not matter.
The dot operator expects an identifier on the right, and identifiers cannot have dashes (as it is parsed as the minus operator) or start with a number. You can use the square brackets to access it as follows:
The underscore “_” is valid to use in an identifier