Why does SpEL not support the unicode variable? How to work?

Code first

@Test public void tryUnicode() { SpelExpressionParser parser = new SpelExpressionParser(); Object rootObject = new Object() { public String getName() { return "wener"; } public String get名字() { return getName(); } }; // ok assert parser.parseExpression("name").getValue(rootObject).equals("wener"); // not ok assert parser.parseExpression("名字").getValue(rootObject).equals("wener"); } 

For some time, we just need a Unicode name, it is more friendly to our custom in the template. Spel is simple, simple and built-in, I do not want to use another EL solution, how can I solve this problem?

EDIT

In org.springframework.expression.spel.standard.Tokenizer#isIdentifier they only accept isAlphabetic(ch) || isDigit(ch) || ch == '_' || ch == '$'; isAlphabetic(ch) || isDigit(ch) || ch == '_' || ch == '$'; unicode support, but java id allowed unicode, sad.

+6
source share
1 answer

You can hack it - check and change the source as needed. Or you can create a problem or develop a repository, add Unicode support and send a transfer request. There is no other way. As for why, I would like to know this myself.

0
source

Source: https://habr.com/ru/post/971913/


All Articles