jsonista icon indicating copy to clipboard operation
jsonista copied to clipboard

annotations support

Open mpenet opened this issue 5 years ago • 2 comments

I am trying to exclude a field from the serialized output (it causes a cyclic serialization issue -> stack overflow). I cannot (ab)use a custom mapper, it's out of my control in that case (in a dependency).

This seems to be working with deftype but not defrecord:

(deftype D [a])
(deftype T [^{com.fasterxml.jackson.annotation.JsonIgnore true} a])
(defrecord R [^{com.fasterxml.jackson.annotation.JsonIgnore true} a])

;; just so that it doesn't blow up on the deftype
(def mapper
  (doto (object-mapper {})
    (.configure com.fasterxml.jackson.databind.SerializationFeature/FAIL_ON_EMPTY_BEANS false)))

(write-value-as-string (D. 1) mapper) -> {"a": 1}
(write-value-as-string (T. 1) mapper) -> {}
(write-value-as-string (R. 1) mapper) -> {"a": 1}

I would expect it to work the same way for records. I guess this might have to do with the custom serializer for Maps in jsonista.

mpenet avatar Mar 17 '20 15:03 mpenet

I guess the record gets interpreted as a java.util.Map and serialized via a MapSerializer which doesn't then interpret annotations since a java.util.Map isn't a POJO.

viesti avatar Mar 21 '20 12:03 viesti

Yep

mpenet avatar Mar 21 '20 12:03 mpenet