alibaba / fastjson

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
https://github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn
Apache License 2.0
25.74k stars 6.5k forks source link

反序列化java.awt.Font 包含@type是报syntax error, @type #3634

Open rw12306 opened 3 years ago

rw12306 commented 3 years ago

image 原参数: "font": { "@type": "java.awt.Font", "name": "宋体", "style": 0, "size": 10 }

image

} else if (key.equalsIgnoreCase("size")) { if (lexer.token() == JSONToken.LITERAL_INT) { size = lexer.intValue(); lexer.nextToken(); } else { throw new JSONException("syntax error"); } } else { --此处会报错 throw new JSONException("syntax error, " + key); } 这里会报错syntax error, @type

Certseeds commented 3 years ago
import com.alibaba.fastjson.JSON;
import org.junit.Test;

public class Issue3634 {
    private static final String willUse = "{\n" +
            "  \"font\": {\n" +
            "    \"@type\": \"java.awt.Font\",\n" +
            "    \"name\": \"宋体\",\n" +
            "    \"style\": 0,\n" +
            "    \"size\": 10\n" +
            "  }\n" +
            "}";

    @Test
    public void test1() {
        JSON.parseObject(willUse);
        JSON.parse(willUse);
    }
}

1.2.75,openjdk8. 没复现成功,@rw12306,能提供复现demo吗?