why SpEL not support unicode variable ? How to work around?
Asked Answered
D

1

6

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");
}

Some time we just need a unicode name, it is more friendly to our custom in template. SpEL is simple ,easy and built-in, I don't 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 == '$'; no unicode support, but java identifier allowed unicode, sad.

Dioxide answered 8/7, 2014 at 11:50 Comment(0)
H
0

You can hack it - check out and modify source as you need. Or you can create issue, or fork the repository, add Unicode support and submit a pull request. There is no other way. As to why, I'd like to know that myself.

Heir answered 29/7, 2014 at 14:4 Comment(2)
Why minus? Please explain, so I can do better next time or maybe even fix this one :)Heir
no -1 from me, but I guess the -1 was because this is basically more of a comment than an answer - the question was "why", so saying "I don't know" is not the answer, even if it's factually true :)Greenstone

© 2022 - 2024 — McMap. All rights reserved.