Skip to content

Simple example for mapping attributes #279

Closed Answered by romm
TutanRamon asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @TutanRamon, I have several suggestion to make:

It seems that the request arguments describe a list of StockData, so it looks like you need to map not to the class directly, rather a list of it:

(new \CuyZ\Valinor\MapperBuilder())
    ->mapper()
    ->map('list<' . StockData::class . '>', /* … */);

Note that it would also work with an array. You can find the list of available types in the documentation.

Next, the request object seems to be able to provide an array of raw data, you probably don't need to use the JsonSource. You probably can do something like the example below, as long as you provide an iterable to the mapper.

(new \CuyZ\Valinor\MapperBuilder())
    ->mapper()
    ->map('l…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@TutanRamon
Comment options

Answer selected by TutanRamon
Comment options

You must be logged in to vote
1 reply
@romm
Comment options

romm Dec 8, 2022
Maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants