Skip to content
Advertisement

How to conditionally serialize a field

I want to conditionally serialize a field. I figured out how to conditionally ignore a field with

JavaScript

But what I really want to do is to redact the field. So if I have

JavaScript

I get

JavaScript

Field2 is correctly ignored. But what I really want is

JavaScript

I have another annotation, @MaskSensitiveData

JavaScript

So what I want to do is combine them. So if a field has the special annotation and I am using my introspector, only then, do I want to redact the field. Otherwise, the field should be serialized normally.

Advertisement

Answer

Instead of overriding method hasIgnoreMarker in NologIntrospector. You need to override findSerializer. This way when your introspector is enabled the custom serializer will be used else it will use the original serializer.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement