Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

annotations support #28

Open
mpenet opened this issue Mar 17, 2020 · 2 comments
Open

annotations support #28

mpenet opened this issue Mar 17, 2020 · 2 comments

Comments

@mpenet
Copy link

mpenet commented Mar 17, 2020

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.

@viesti
Copy link
Member

viesti commented Mar 21, 2020

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.

@mpenet
Copy link
Author

mpenet commented Mar 21, 2020

Yep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants