question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Associate property with two types

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
zokabazokacommented, Mar 14, 2019

this would be example of JSON in question:

{
  "test": {
    "first": "123",
    "second": 123
  }
}

and when empty:

{
  "test": []
}

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.

0reactions
webfrea-kcommented, Mar 20, 2019

Works like a charm! Thanks again @sandwwraith 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Commutative, Associative, and Distributive Properties
A. The associative property states that when adding or multiplying, the grouping symbols can be rearranged and it will not affect the result....
Read more >
What is Associative Property? Definition, Facts and Examples
Associative property is defined as, when more than two numbers are added or multiplied, the result remains the same, irrespective of how they...
Read more >
Associative Property - Definition, Examples - Cuemath
The associative property states that the sum or the product of three or more numbers does not change if they are grouped in...
Read more >
Associative, Distributive and Commutative Properties
Associative law states that the order of grouping the numbers does not matter. This law holds for addition and multiplication but it doesn't ......
Read more >
Associative property with a two element set
"Within an expression containing two or more occurrences in a row of the same associative operator, the order in which the operations are ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found