Skip to content

Commit

Permalink
Update strip-nils to only strip nils, not empty strings, maps, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicfreeston committed Jul 11, 2024
1 parent 16a826a commit c8b12a8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
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
4 changes: 2 additions & 2 deletions test/jsonista/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
(testing ":pretty"
(is (= "{\n \"hello\" : \"world\"\n}" (j/write-value-as-string data (j/object-mapper {:pretty true})))))
(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}))))))
(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 c8b12a8

Please sign in to comment.