Associate property with two types
See original GitHub issueI have a JSON property which is Object {}
if populated, and List []
if empty. Is it possible to skip such property (or set it to null) in custom deserializer? I have a deserialize
code which handles the object part, and now I need to handle the list part. If I just skip it by not calling decoder.decode...()
, the next object throws error as it is not on the correct position of a source string.
As a workaround we have implemented EmptyListDescriptor: SerialDescriptor
which overrides kind
with LIST
.
If the initial deserialization fails, we try to deserialize again with custom descriptor (emptyList) which works ok for now.
Is there any other (better) way of achieving this?
Feature suggestion: Add actual kind
to Decoder
interface (to easily switch descriptors - without try-catch).
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top GitHub Comments
this would be example of JSON in question:
and when empty:
in deserialize we now handle this with try catch and in catch block we fallback to different descriptor. Ideally we would like to know what kind of JSON property are we planing to deserialize (JSON Object, JSON Array) and that would be a feature request 😃 because in our case we can’t change the JSON due to the legacy reasons.
Works like a charm! Thanks again @sandwwraith 😃