Collection serializers and deserializer should be contextual #155
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Fix #154
Collection-like serializers and deserializers should be contextual to handle properties of the element defined outside of the collection. For example, in collection
List<Date>
, handling@JsonFormat
defined forDate
:All the collection-like serializers and deserializers are concerned: serializers and deserializers for Set, Seq, Array, Priority-Queue, List, and their derived classes.
Serialization
VAVR-Jackson does not handle the serialization directly. We emulate the VAVR type to Java type. Then, let the serializer provider to find the right serializer to handle the logic. To support contextualization, we save the bean property in
ArraySerializer
, and pass this property to serializer provider for the lookup:Since serializer should be immutable (see comment), by "saving the bean property", it actually means creating a new serializer with all the existing info and a new bean property.
Deserialization
VAVR-Jackson handles the deserialization directly. In Array-Deserializer, implement the add-on interface
ContextualDeserializer
and perform lookup to find the appropriated serializer for the elements of the collection. The logic is mainly inspired from previous PRs (#144, #147) and Jackson Databind.Additional Notes
Other serializers and deserializers may have the same problem. I need to spend some time to them in future PRs...