|
610 | 610 | (defn- write-generic [x out options] |
611 | 611 | (if (.isArray (class x)) |
612 | 612 | (-write (seq x) out options) |
613 | | - (throw (Exception. (str "Don't know how to write JSON of " (class x)))))) |
| 613 | + ((:default-write-fn options) x out options))) |
614 | 614 |
|
615 | 615 | (defn- write-ratio [x out options] |
616 | 616 | (-write (double x) out options)) |
|
648 | 648 | ;; Maybe a Java array, otherwise fail |
649 | 649 | (extend java.lang.Object JSONWriter {:-write write-generic}) |
650 | 650 |
|
| 651 | +(defn- default-write-fn [x out options] |
| 652 | + (throw (Exception. (str "Don't know how to write JSON of " (class x))))) |
| 653 | + |
651 | 654 | (def default-write-options {:escape-unicode true |
652 | 655 | :escape-js-separators true |
653 | 656 | :escape-slash true |
654 | 657 | :sql-date-converter default-sql-date->instant-fn |
655 | 658 | :date-formatter java.time.format.DateTimeFormatter/ISO_INSTANT |
656 | 659 | :key-fn default-write-key-fn |
657 | 660 | :value-fn default-value-fn |
| 661 | + :default-write-fn default-write-fn |
658 | 662 | :indent false |
659 | 663 | :indent-depth 0 ;; internal, to track nesting depth |
660 | 664 | }) |
|
713 | 717 | returns itself, the key-value pair will be omitted from the |
714 | 718 | output. This option does not apply to non-map collections. |
715 | 719 |
|
| 720 | + :default-write-fn function |
| 721 | +
|
| 722 | + Function to handle types which are unknown to data.json. Defaults |
| 723 | + to a function which throws an exception. Expects to be called with |
| 724 | + three args, the value to be serialized, the output stream, and the |
| 725 | + options map. |
| 726 | +
|
716 | 727 | :indent boolean |
717 | 728 |
|
718 | 729 | If true, indent json while writing (default = false)." |
|
0 commit comments