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.
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.
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:
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.