Fork me on GitHub
#ring-swagger
<
2016-01-19
>
ljosa19:01:56

I'm trying to use compojure.api with aleph. That works beautifully for the most part, but now I have a route where I want to return a manifold stream to aleph so I can stream results with server-sent events. Somewhere along the way, something tries to JSON encode the manifold stream:

com.fasterxml.jackson.core.JsonGenerationException: Cannot JSON encode object of class: class manifold.stream.async.CoreAsyncSource: [email protected]
	at cheshire.generate$generate.invoke(generate.clj:148)
	at cheshire.core$generate_string.invoke(core.clj:31)
	at ring.middleware.format_response$make_json_encoder$fn__18470.invoke(format_response.clj:210)
	at ring.middleware.format_response$wrap_format_response$fn__18460.invoke(format_response.clj:193)
	at ring.middleware.keyword_params$wrap_keyword_params$fn__18594.invoke(keyword_params.clj:35)
	at ring.middleware.nested_params$wrap_nested_params$fn__18644.invoke(nested_params.clj:84)
	at ring.middleware.params$wrap_params$fn__18728.invoke(params.clj:64)
	at compojure.api.middleware$wrap_options$fn__22290.invoke(middleware.clj:93)
	at clojure.lang.AFn.applyToHelper(AFn.java:154)
	at clojure.lang.AFn.applyTo(AFn.java:144)
	at clojure.lang.AFunction$1.doInvoke(AFunction.java:29)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at aleph.http.server$wrap_stream__GT_input_stream$fn__13574.invoke(server.clj:403)
	at aleph.http.server$handle_request$fn__13492$f__2183__auto____13493.invoke(server.clj:153)
	at clojure.lang.AFn.run(AFn.java:22)
	at io.aleph.dirigiste.Executor$Worker$1.run(Executor.java:49)
	at java.lang.Thread.run(Thread.java:745)
How can I tell it not to?

juhoteperi19:01:48

Not sure if CoreAsyncSource implements collection, that would case the second condition to be true

juhoteperi19:01:13

Have you defined return schema for the route? That always forces response encoding

ljosa19:01:04

> (coll? (ms/->source (a/chan)))
false

ljosa19:01:36

I have :return s/Any on the route … let me try to remove it

ljosa19:01:03

💥 that fixed it! thank you!