hmm, trying to find a way to do spec coercion and validation in such a way, that in coming JSON keys would be first transformed
meaning that "foo_bar"
comes in and I want to handle those as :foo-bar
I guess Muuntaja is my answer
@niklas.collin yes, jsonista reade has an example on encoding & decoding mao keys. Sadly, the apidocs don't follow that.
Another option is to do a custom map transformer for json in spec-tools.
here's an example of such: https://github.com/metosin/spec-tools/blob/master/src/spec_tools/transform.cljc#L108-L111
CompilerException java.lang.AssertionError: In Muuntaja 0.6.0+ the default JSON formatter has changed
from Cheshire to Jsonita. Changed options:
:key-fn => :encode-key-fn & :decode-key-fn
:bigdecimals? => :bigdecimals
Well this was a nice suprise 👍hmm, I thought compojure-api would use automatically the spectools :decode/string
under the hood?
currently failing spec validations since there's a string coming in which should be coerced to a number
for json? It's :decode/json
I mean, I have a spec definition such as:
(s/def ::foo
(spec/spec
{:spec integer?
:decode/string str->integer}))
and that is used deep within my spec definitions
still should use :decode/json
?
well, I can always try
right, so it seems
not obvious
just a small feedback 🙂
anyway, got it working 👍
great! PRs for obvious docs most welcome ;)
when I have time 😄
Time, that one resource you are always lacking