Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.1
-
Fix Version/s: 1.2
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
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.
Ok, finally started actually working on this.
Adding SerializationConfig.Feature.USE_STATIC_TYPING for global defaults (defaults to false, to use dynamic), and a new property for per-class/method/field annotation @JsonSerialize, typing, with enumerated value JsonSerialize.Typing
{ DYNAMIC, STATIC }.