Skip to content

Commit

Permalink
Merge pull request #78 from dominicfreeston/strip-nils-only-strip-nils
Browse files Browse the repository at this point in the history
Update strip-nils to only strip nils, not empty strings, maps, etc
  • Loading branch information
opqdonut authored Aug 9, 2024
2 parents 16a826a + f8ef2ca commit dae5171
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/clj/jsonista/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
(:order-by-keys options) (.configure SerializationFeature/ORDER_MAP_ENTRIES_BY_KEYS true)
(:pretty options) (.enable SerializationFeature/INDENT_OUTPUT)
(:bigdecimals options) (.enable DeserializationFeature/USE_BIG_DECIMAL_FOR_FLOATS)
(:strip-nils options) (.setSerializationInclusion JsonInclude$Include/NON_EMPTY)
(:strip-nils options) (.setSerializationInclusion JsonInclude$Include/NON_NULL)
(:do-not-fail-on-empty-beans options) (.disable SerializationFeature/FAIL_ON_EMPTY_BEANS)
(:escape-non-ascii options) (doto (-> .getFactory (.enable JsonGenerator$Feature/ESCAPE_NON_ASCII)))))]
(doseq [module (:modules options)]
Expand Down
3 changes: 3 additions & 0 deletions test/jsonista/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
(testing ":strip-nils"
(let [data-with-nils {:hello "world" :goodbye nil}]
(is (= "{\"hello\":\"world\"}" (j/write-value-as-string data-with-nils (j/object-mapper {:strip-nils true}))))))
(testing ":strip-nils doesn't strip other empties"
(let [data-with-nils {:hello "world" :goodbye nil :empty-string "" :empty-map {}}]
(is (= "{\"hello\":\"world\",\"empty-string\":\"\",\"empty-map\":{}}" (j/write-value-as-string data-with-nils (j/object-mapper {:strip-nils true}))))))
(testing ":escape-non-ascii"
(is (= "{\"imperial-money\":\"\\u00A3\"}" (j/write-value-as-string {:imperial-money "£"} (j/object-mapper {:escape-non-ascii true})))))
(testing ":date-format"
Expand Down

0 comments on commit dae5171

Please sign in to comment.