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
I wonder that how to deserialize top-level sequences into an object. I found that something similar already exists in this library, but limited to CSV.
It deserializes the array without errors, but the type of items becomes associative array rather than MyItem. Seems like the SequenceField attribute is ignored if flatten: true.
Context
I am refactoring the API in an old project. Some of the routes accepts JSON arrays as its body, and I found that Serde does not provide a simple way to deserialize the arrays into strictly-typed objects.
Possible implementation
Generalize the feature existing in the CSV handler. The analogy in Rust's serde (transparent) could be a good API design for this feature.
Your environment
Version used: PHP 8.3
Operating system and version: Arch Linux
Link to your project: N/A
The text was updated successfully, but these errors were encountered:
I think you just need to remove the Flatten directive?
I just ran a quick test using the PointList class, used in the CSV formatter tests. It worked fine with the standard formatters. What part of CSV-specific handling do you need?
Can you PR a failing test to better describe what you're trying to do? That would make it easier to determine what to do with it.
Detailed description
I wonder that how to deserialize top-level sequences into an object. I found that something similar already exists in this library, but limited to CSV.
For example, I have such a PHP array
And the DTOs
It seems that I cannot deserialize
$data
into an instance ofMyList
. I tried adding these attributes toMyList#items
It deserializes the array without errors, but the type of items becomes associative array rather than
MyItem
. Seems like theSequenceField
attribute is ignored ifflatten: true
.Context
I am refactoring the API in an old project. Some of the routes accepts JSON arrays as its body, and I found that Serde does not provide a simple way to deserialize the arrays into strictly-typed objects.
Possible implementation
Generalize the feature existing in the CSV handler. The analogy in Rust's serde (transparent) could be a good API design for this feature.
Your environment
The text was updated successfully, but these errors were encountered: