从Spring Boot RestController返回Clojure PersistentVector

时间:2018-12-12 22:28:11

标签: rest spring-boot clojure jackson

我正在尝试从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的子类型)?

1 个答案:

答案 0 :(得分:0)

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

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

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