You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Workaround: In the deserialization of the Author type, we could check if we're dealing with a mapping and delegate to the ObjectTypeConverter instead. (The serialization case is a bit more tricky if you want to maintain the state mode which the value was deserialized and we can think about that in a different issue).
We can require type-hint adapters to store the original that a type was adapter from, allowing the ObjectMapper to look for an alternative converter for the original type if a ConversionError caused by an incompatible source value type (only during deserialization)
The text was updated successfully, but these errors were encountered:
Use case: A type that supports multiples representations and modes of de-/serialization.
Example: Imagine a dataclass
Author
that can be deserialized from a string or from a mapping.We can register a converter from/to string like this:
Drawbacks:
Now
Author
can only be de-/serialized to/from a string.It only works in
ObjectMapper
because of the type-hint adapter stop condition:https://github.com/NiklasRosenstein/databind/blob/543555f173215d184c33a5d7b9e0122d76284f11/databind.core/src/databind/core/mapper/objectmapper.py#L43-L56
Workaround: In the deserialization of the
Author
type, we could check if we're dealing with a mapping and delegate to theObjectTypeConverter
instead. (The serialization case is a bit more tricky if you want to maintain the state mode which the value was deserialized and we can think about that in a different issue).Potential solution:
ObjectMapper
to look for an alternative converter for the original type if aConversionError
caused by an incompatible source value type (only during deserialization)The text was updated successfully, but these errors were encountered: