Unable to deserialize nested types of union and tuple
See original GitHub issuePython 3.9 pyserde[toml]==0.3.1
from dataclasses import dataclass
from typing import Union
from serde import toml, deserialize
@deserialize
@dataclass
class TestClass:
a: Union[None, Union[int, float], tuple[Union[int, float], Union[int, float]]]
if __name__ == '__main__':
test_class = toml.from_toml(TestClass, 'a = [4, 1]')
print(test_class)
Running the above code will throw an error:
serde.core.SerdeError: Can not deserialize [4, 1] of type List into Union[NoneType, int, float, Tuple[Union[int, float], Union[int, float]]]. Reason: 'union_de_int_float'
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
c# - JSON Deserialization Despair (unable to ... - Stack Overflow
You basically need to tell the Serializer all the types it may encounter while serializing/deserializing your object.
Read more >Developers using JsonSerializer want it to handle common F# ...
We should make sure that the JSON serializer can handle types / structures that commonly occur in F#, such as Discriminated unions Option ......
Read more >Jackson Exceptions - Problems and Solutions - Baeldung
Here we'll try to deserialize an instance from class Zoo that has a ... This exception is thrown if Jackson can't access the...
Read more >Migrate from Newtonsoft.Json to System.Text.Json - .NET
Polymorphic deserialization. Newtonsoft.Json has a TypeNameHandling setting that adds type-name metadata to the JSON while serializing. It uses ...
Read more >Body - Nested Models - FastAPI
Declare a list with a type parameter. To declare types that have type parameters (internal types), like list , dict , tuple :...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, but the recursion should happen in iter_unions there it should be:
I did not really test Unions in Unions, the only existing test is too simple and python is actually optimizing it away 😃 Sadly the fix in
iter_unions
produces a follow up issue. A nested tuple is flattened, but it shouldn’t.We probably need an own render mode that is used within union functions similar to
DeField.iterbased
to prevent this.Hi @uheee
Just wanted to let you know v0.3.2 is pushed to PyPI! 🙂