Open balthild opened 9 months ago
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.
That's strange... I tried removing #[Field(flatten: true)]
before and it didn't work. I tried in an MWE just now, and it still doesn't work.
The MWE: https://gist.github.com/balthild/37f72106f775e6b25417d4e778a38d5b
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