Dear Jackson community,

we are trying to enhance the Jackson serializer in one of our project. We 
want to hide / ignore certain fields from certain objects conditionally. 
Means certain fields should only be serialized to JSON when a specific 
condition is true. We want to restrict certain fields based on the current 
user access.

Our idea is to pass a auth context to Jackson, this auth context will 
contain information which fields the current user can see and which not.

The difficult part now comes how we can hide certain fields based on this.

What we already considered:

   - JsonIgnore annotation (does not work, its static and not based on 
   conditions)
   - JsonInclude annotation (does not work, its static and not based on 
   conditions)
   - JsonView (not very practical, we would need to create one view class 
   for each field in all objects)
   - Using custom serializer as described here 
   
https://www.baeldung.com/jackson-serialize-field-custom-criteria#2-custom-serializer
 (Can 
   only work to hide a complete object, not just certain fields)

Does anyone has a good approach in Jackson to exclude / hide / ignore 
certain fields dynamically?

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/a2a44c71-3e80-4da6-ab35-eabb342e1851n%40googlegroups.com.

Reply via email to