Type: New Feature
Affects Version/s: 1.1
Fix Version/s: 1.2
Number of attachments :
For some use cases it is preferable to use declared type when serializing, instead of actual concrete type.
Type to use has to be one of super-types (super-class or interface).
There are multiple possible ways to implement such functionality, including adding a togglable feature and/or annotations.
One simple way seems to be to just add a new writeValue() method (or methods) in ObjectMapper that takes an extra argument; type (Class) of the value to use as the declared type.
Calling this method will indicate that declared types are to be used instead of runtime types throughout dependency chain.
Extra argument is needed since there is no real declared type for the root value.
Implementing functionality this way means that serialization context has to carry decision (declared or actual (runtime) types?) through the process – need to see if that is a workable strategy.