98 Star 569 Fork 123

闲.大赋(李家智) / Beetl

 / 详情

3.0.0.M4版本自动调用get方法的代码不够灵活

待办的
创建于  
2019-05-31 10:24

该问题是怎么引起的?

beetl的这个自动获取属性的方法很不错。但是返回值被限定成为Object类本身,任何Object的子类都不行,不够灵活。其实返回值只要不为void就行。
beetl的自动获取属性的方法

重现步骤

1.测试用例java类:
@test
public void testJsonParse() throws Exception {
//上面的代码省略...
//rootNode是一个com.fasterxml.jackson.databind.node.ObjectNode对象,由"{a:{name:'hello',age:18},b:[1,2,3]}"解析生成。

	Template t = gt.getTemplate("/jsonparse.html");
	this.bind(t, "b", rootNode);
	String str = t.render();
	System.out.println(str);
}

2.jsonparse.html文件:
${b["a"]["age"]}
${b["b"][0]}
${b.a.age}
${b.b[0]}

报错信息

java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.node.ObjectNode.get(Ljava/lang/String;)Ljava/lang/Object;
at com.fasterxml.jackson.databind.node.ObjectNode$AttributeAccess.value(Unknown Source)
at org.beetl.core.statement.VarSquareAttribute.evaluate(VarSquareAttribute.java:59)
at org.beetl.core.statement.VarRef.evaluate(VarRef.java:99)
at org.beetl.core.statement.PlaceholderST.execute(PlaceholderST.java:30)
at org.beetl.core.statement.Program.run(Program.java:69)
at org.beetl.core.statement.Program.execute(Program.java:61)
at org.beetl.core.Template.renderTo(Template.java:130)
at org.beetl.core.Template.renderTo(Template.java:90)
at org.beetl.core.Template.render(Template.java:78)
at org.beetl.core.exp.JsonTest.testJsonParse(JsonTest.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:121)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

评论 (1)

xfzhu2008 创建了任务

好的,信息挺详细的,我看看,我建议暂时先改成Object吧

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
29 xiandafu 1678706040
Java
1
https://gitee.com/xiandafu/beetl.git
git@gitee.com:xiandafu/beetl.git
xiandafu
beetl
Beetl

搜索帮助