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

Registering a converter for a type might incorrectly affect serializer construction #4662

Open
odrotbohm opened this issue Aug 14, 2024 · 1 comment
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@odrotbohm
Copy link

odrotbohm commented Aug 14, 2024

Describe your Issue

Assume you have an interface / implementation arrangement for values to be serialized:

interface MyInterface {
  String getProperty();
}
class MyImplementation implements MyInterface {

  String getProperty() { … }
  String getAnotherProperty() { … }
}

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.

References

@odrotbohm odrotbohm added the to-evaluate Issue that has been received but not yet evaluated label Aug 14, 2024
@cowtowncoder
Copy link
Member

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:

#2045

which is one of "Most Wanted" issues, too.

So contribution for adding would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-evaluate Issue that has been received but not yet evaluated
Projects
None yet
Development

No branches or pull requests

2 participants