I'm seeing this kind of error after pathom Index Explorer is trying to serialize the entire context and push it across the wire.
java.lang.Exception: Not supported: class com.wsscode.pathom.connect$fn__54398
java.lang.RuntimeException: java.lang.Exception: Not supported: class com.wsscode.pathom.connect$fn__54398
clojure.lang.ExceptionInfo: Malformed application/transit+json in :muuntaja/encode
format: "application/transit+json"
type: :muuntaja/encode
What is the best way to configure muuntaja to simply ignore things it can't encode correctly in application/transit+json
?
Is there a way to configure a default handler?
You are returning a function, which can't be serialized. I don't think disabling encoding helps here. I would double-check how to serialize the context.
Just trying to think this through, I've tried e.g.:
(def generic-function-writer
(transit/write-handler
(constantly "fn")
(fn [v] (pr-str v))
(fn [v] (pr-str v))))
(def muuntaja-instance
(muuntaja/create
(-> muuntaja/default-options
(assoc-in
[:formats "application/transit+json" :encode-opts]
{:handlers {java.util.function.Function generic-function-writer}}))))
But it doesn't seem to be called (would it match the java.util.function.Function
?
you can set response "Content-Type"
manually to disable the automatic encoding.
... but, will most likely to blow up in the web server. Maybe you should invoke the function yourself?
To clarify, I'm using reitit-http
and my router has {:data {:muuntaja my-muuntaja-instance}}
.
I expect, that the (interceptor.muuntaja/format-response-interceptor)
should pick up this custom muuntaja instance?
This is a weird setup - I didn't expect to get hit with a serialization problem like this. But it looks like a real thing, and the expected workaround for now: https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/connect/exploration.html#_fixing_transit_encoding_issues
I've done as you suggested for now @ikitommi - just invoking the custom transit writer myself for this specific route. I'd still like to circle back to this later and figure out a nicer solution. Thanks!