这(可怕;不问;我不能修改数据模型或结构)的表达不工作:Freemarker 2.3.23是否正确处理可变参数?
${statics["java.nio.file.Files"].write(statics["java.nio.file.Paths"].get("/foo/bar.stuff"), statics["java.nio.charset.Charset"].forName("UTF-8").encode(someStringContent).array(), enums["java.nio.file.StandardOpenOption"].WRITE)}
型号代码:
model.addAttribute("statics", new BeansWrapperBuilder(Configuration.VERSION_2_3_23).build().getStaticModels());
model.addAttribute("enums", new BeansWrapperBuilder(Configuration.VERSION_2_3_23).build().getEnumModels());
简而言之,它是采用一些Freemarker字符串内容的(总体)方式,将其变成byte[]
阵列,并将其写入Freemarker内部的/foo/bar.stuff
路径。
的错误指示的Freemarker不能选择适当的可变参数方法:
Error executing FreeMarker template
FreeMarker template error:
When trying to call the non-varargs overloads:
No compatible overloaded variation was found; can't convert (unwrap) the 3rd argument to the desired Java type.
The FTL type of the argument values were: extended_hash+string (sun.nio.fs.UnixPath wrapped into f.e.b.StringModel), sequence (byte[] wrapped into f.t.DefaultArrayAdapter$ByteArrayAdapter), extended_hash+string (java.nio.file.StandardOpenOption wrapped into f.e.b.StringModel).
When trying to call the varargs overloads:
Multiple compatible overloaded variations were found with the same priority.
The Java type of the argument values were: sun.nio.fs.UnixPath, byte[], java.nio.file.StandardOpenOption.
The matching overload was searched among these members:
static java.nio.file.Files.write(java.nio.file.Path, Iterable, java.nio.file.OpenOption...),
static java.nio.file.Files.write(java.nio.file.Path, Iterable, java.nio.charset.Charset, java.nio.file.OpenOption...),
static java.nio.file.Files.write(java.nio.file.Path, byte[], java.nio.file.OpenOption...)
我试过其他黑客,包括创建使用java.lang.reflect.Array#newInstance(Class, int)
正确类型的数组,但这并没有帮助。
我假设这是不可能的?
您是否有权访问定义静态的代码?你能粘贴它吗? – Charlie
如果您不介意,我会粘贴模型代码以获取您看到的错误。如果它与你的不一样,请纠正它。 – Charlie
莱尔德,你的静态BeanWrapper是用EXPOSE_ALL暴露级别构建的吗? – Charlie