Affects: Spring Framework 5.3.13


SpEL does not support Chinese.

Example:

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    static class Simple {
        private String 张三;
    }

    @Test
    void testSpel() {
        ExpressionParser parser = new SpelExpressionParser();
        Expression exp = parser.parseExpression("张三 == null ? 'World' : 张三");
        Simple rootObject = new Simple("test");

        Object value = exp.getValue(rootObject);
        System.out.println(value);

    }

Comment From: k143408

Try

ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("'你好,世界!'");

String message = (String) expression.getValue();
System.out.println(message); // Prints "你好,世界!"

Comment From: sbrannen

Try

```java ExpressionParser parser = new SpelExpressionParser(); Expression expression = parser.parseExpression("'你好,世界!'");

String message = (String) expression.getValue(); System.out.println(message); // Prints "你好,世界!" ```

@k143408, your example demonstrates SpEL's support for Chinese characters within a String literal.

Whereas, @changyoutianxia's example uses Chinese characters in a property name (i.e., a getter method in the root context object).

Comment From: sbrannen

Related Issues

  • 30602

Comment From: sbrannen

SpEL does not support Chinese.

This is a known (although undocumented) limitation of SpEL.

Specifically, the SpEL parser imposes the following restrictions on identifiers (property names, field names, and variable names).

('a'..'z'|'A'..'Z'|'_'|'$') ('a'..'z'|'A'..'Z'|'_'|'$'|'0'..'9'|DOT_ESCAPED)*

With regard to letters, only the letters A through Z (ignoring case) are supported in identifiers.

Since this limitation has been in place since SpEL was introduced, we do not plan to modify the current behavior for Spring Framework 6.0.x or previous versions of the framework.

However, we will modify the SpEL Tokenizer to support additional character sets for Spring Framework 6.1.