从 Spring Boot RestController 返回 Clojure PersistentVector
Posted
技术标签:
【中文标题】从 Spring Boot RestController 返回 Clojure PersistentVector【英文标题】:Returning a Clojure PersistentVector from a Spring Boot RestController 【发布时间】:2019-05-14 02:36:02 【问题描述】:我正在尝试从 Spring Boot RestController
方法返回 Clojure PersistentVector
:
@GetMapping("example")
public PersistentVector someVector()
return PersistentVector.create(42, "hello");
但是,Spring Boot 似乎将PersistentVector
视为一个函数(它是Runnable
和Callable
的子类型):
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】:列表和函数的混淆可以通过在向量上显式调用.iterator()
来解决:
@GetMapping("example")
public Iterator someVector()
// ~~~~~~~~
return PersistentVector.create(42, "hello").iterator();
// ~~~~~~~~~~~
也许不是最干净的解决方案,但嘿,它完成了工作!
【讨论】:
以上是关于从 Spring Boot RestController 返回 Clojure PersistentVector的主要内容,如果未能解决你的问题,请参考以下文章
从 Spring Boot 1.5 升级时为 Spring Boot 2.0 acuator 框架配置安全性