Код: Выделить всё
class SearchResult
{
/**
* @var Collection
*/
private Collection $details;
public function __construct() {
$this->details = new ArrayCollection();
}
public function getDetails(): Collection
{
return $this->details;
}
public function setDetails(Collection $details): SearchResult
{
$this->details = $details;
return $this;
}
public function addDetails(Details $details): self
{
if (!$this->details->contains($details)) {
$this->details[] = $details;
}
return $this;
}
}
Код: Выделить всё
class Details
{
private string $name;
private string $ticker;
private ?string $homepageUrl = null;
private ?string $description = null;
private ?string $currency = null;
private ?int $sicCode = null;
private ?string $sicDescription = null;
public function getName(): string
{
return $this->name;
}
public function setName(string $name): Details
{
$this->name = $name;
return $this;
}
public function getTicker(): ?string
{
return $this->ticker;
}
public function setTicker(string $ticker): Details
{
$this->ticker = $ticker;
return $this;
}
public function getHomepageUrl(): ?string
{
return $this->homepageUrl;
}
public function setHomepageUrl(?string $homepageUrl): Details
{
$this->homepageUrl = $homepageUrl;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): Details
{
$this->description = $description;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(?string $currency): Details
{
$this->currency = $currency;
return $this;
}
public function getSicCode(): ?int
{
return $this->sicCode;
}
public function setSicCode(?int $sicCode): Details
{
$this->sicCode = $sicCode;
return $this;
}
public function getSicDescription(): ?string
{
return $this->sicDescription;
}
public function setSicDescription(?string $sicDescription): Details
{
$this->sicDescription = $sicDescription;
return $this;
}
}
Код: Выделить всё
#[Route('/handle', name: 'handle', methods: ['POST'])]
public function handle(#[MapRequestPayload] SearchResult $searchResult): JsonResponse
{
// Do something here
return new JsonResponse();
}
Код: Выделить всё
{
"details": [
{
"name": "Apple Inc",
"ticker": "AAPL",
"homepage_url": null,
"description": null,
"currency": null,
"sic_code": null,
"sic_description": null
},
{
"name": "Tesla Inc",
"ticker": "TSLA",
"homepage_url": null,
"description": null,
"currency": null,
"sic_code": null,
"sic_description": null
}
]
}
Заранее спасибо!
Подробнее здесь: https://stackoverflow.com/questions/788 ... te-to-nest
Мобильная версия