Skip to content

Commit 6ba1027

Browse files
committed
Add support for SerializedName attributes
1 parent d6a0c59 commit 6ba1027

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
"is_static" => true
3+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AutoMapper\Tests\AutoMapperTest\ConstructorWithSerializedName;
6+
7+
use AutoMapper\Tests\AutoMapperBuilder;
8+
use Symfony\Component\Serializer\Attribute\SerializedName;
9+
10+
final readonly class Bar
11+
{
12+
public function __construct(
13+
#[SerializedName('is_static')]
14+
public bool $isStatic
15+
) {
16+
}
17+
}
18+
19+
$autoMapper = AutoMapperBuilder::buildAutoMapper();
20+
21+
22+
return (function () {
23+
$autoMapper = AutoMapperBuilder::buildAutoMapper();
24+
25+
yield 'to_array' => $autoMapper->map(new Bar(true), 'array');
26+
27+
yield 'from_array' => $autoMapper->map(['is_static' => true], Bar::class);
28+
})();

0 commit comments

Comments
 (0)