Muuntaja, a content negotiation & formatting library for Clojure


#1

Happy to announce [metosin/muuntaja "0.6.0-alpha1"], a content negotiation & formatting library for Clojure. Can be used both as a standalone lib or with Ring/Pedestal style web apps.

blogged: https://www.metosin.fi/blog/muuntaja/

It’s an alpha release, we are hoping to get feedback and testing on the changes before finalizing. The biggest changes:

  • change default JSON formatter from Cheshire to Jsonista
  • change the api to create new formats (with fail-fast assertions on the old syntax)
  • supports writing to byte-arrays (enabling NIO)
  • a multi-module layout, with YAML and MessagePack as separate modules

a quick sample:

(require '[muuntaja.core :as m])

(def m (m/create))

(m/encodes m)
; #{"application/json"
;   "application/transit+msgpack"
;   "application/transit+json"
;   "application/edn"}

(m/decodes m)
; #{"application/json"
;   "application/transit+msgpack"
;   "application/transit+json"
;   "application/edn"}

(->> {:olipa "kerran"}
     (m/encode m "application/json"))
; #object[java.io.ByteArrayInputStream]

(->> {:olipa "kerran"}
     (m/encode m "application/json")
     (slurp))
; "{\"olipa\":\"kerran\"}"

(->> {:olipa "kerran"}
     (m/encode m "application/json")
     (m/decode m "application/json"))
; {:olipa "kerran"}

coordinates:


#2

thank you! happy user so far :).