You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you register a StdConverter<MyInterface, MyInterface> to pre-process a value to be serialized, BeanSerializer.createSerializer(…) inspects the converter's target type, and builds a serializer for that explicitly. This causes getAnotherProperty() being lost for serialization as only MyInterface gets inspected, not MyImplementation.
I can see that you cannot simply use the original value's type as source for the serializer creation, as the converter could theoretically convert into any MyInterface implementation. So I wonder how I'd post-process an instance before serialization, but still make sure it gets serialized as this particular instance. I cannot change the declaration of the converter, as I do not control the implementing types.
Is there any other abstraction I could use to get a call for one or each time a certain type is serialized? In this particular case, I do not even need access to the value, as I'd like to log a message only.
If I understand the question, it's whether there is a hook you could register when attempting to serialize a value (instance) of a type. Short answer is "no".
But such feature (pre-serialization hook) has been requested before -- and I think there may be an issue for ... ah, this:
Describe your Issue
Assume you have an interface / implementation arrangement for values to be serialized:
If you register a
StdConverter<MyInterface, MyInterface>
to pre-process a value to be serialized,BeanSerializer.createSerializer(…)
inspects the converter's target type, and builds a serializer for that explicitly. This causesgetAnotherProperty()
being lost for serialization as onlyMyInterface
gets inspected, notMyImplementation
.I can see that you cannot simply use the original value's type as source for the serializer creation, as the converter could theoretically convert into any
MyInterface
implementation. So I wonder how I'd post-process an instance before serialization, but still make sure it gets serialized as this particular instance. I cannot change the declaration of the converter, as I do not control the implementing types.Is there any other abstraction I could use to get a call for one or each time a certain type is serialized? In this particular case, I do not even need access to the value, as I'd like to log a message only.
References
The text was updated successfully, but these errors were encountered: