This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
Update ArrayCaster to accept objects (of the correct class) alongside arrays that get cast like normal #217
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Brendt and co. Thanks for your work on this useful project.
I came across a situation that would be helpful to me if it were altered slightly. I hope it's something that's helpful for others too…
Usually, I build DTO objects by passing the desired child DTO objects. But sometimes I need these same DTOs to be hydrated from serialised arrays.
When using the ArrayCaster to cast arrays into objects, the elements to be cast must be arrays (otherwise an error is generated).
This PR lets you also pass in objects of the desired type (no cast needed), as well as the original behaviour (which casts the array). This way, both situations are covered.
I split the PR up into two commits; The first containing updated tests to show the error, and the second with the updated code. I can squash them if desired.