這(可怕;不問;我不能修改數據模型或結構)的表達不工作: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