我试图从Spring Boot PersistentVector方法返回Clojure RestController:

@GetMapping("example")
public PersistentVector someVector() {
    return PersistentVector.create(42, "hello");
}

但是,似乎Spring Boot会将PersistentVector视为一个函数(它是RunnableCallable的子类型):
clojure.lang.ArityException: Wrong number of args (0) passed to: PersistentVector

at clojure.lang.AFn.throwArity(AFn.java:429) ~[clojure-1.9.0.jar:na]
at clojure.lang.AFn.invoke(AFn.java:28) ~[clojure-1.9.0.jar:na]
at clojure.lang.AFn.call(AFn.java:18) ~[clojure-1.9.0.jar:na]

at org.springframework.web.context.request.async.WebAsyncManager.lambda$startCallableProcessing$4(WebAsyncManager.java:323) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_181]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_181]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]

如何告诉Spring Boot将PersistentVector视为List(它也是List的子类型)?

最佳答案

可以通过在 vector 上显式调用.iterator()来解决list和函数之间的混淆:

@GetMapping("example")
public Iterator someVector() {
    // ~~~~~~~~
    return PersistentVector.create(42, "hello").iterator();
}                                           // ~~~~~~~~~~~

也许不是最干净的解决方案,但嘿,它可以完成工作!

关于rest - 从Spring Boot RestController返回Clojure PersistentVector,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53752344/

10-11 06:22