FasterXML / FasterXML/jackson-databind
Registering a converter for a type might incorrectly limit serializer construction for actual type
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 1.5k
- Avg merge
- 3d 6h
- Merged PRs (30d)
- 28
Description
### Describe your Issue
Assume you have an interface / implementation arrangement for values to be serialized:
```java
interface MyInterface {
String getProperty();
}
class MyImplementation implements MyInterface {
String getProperty() { … }
String getAnotherProperty() { … }
}
```
If you register a `StdConverter` 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
* spring-projects/spring-boot#41856
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.