diff --git a/src/HateoasBuilder.php b/src/HateoasBuilder.php index fcbd4594..e7a2f9ac 100644 --- a/src/HateoasBuilder.php +++ b/src/HateoasBuilder.php @@ -192,6 +192,9 @@ public function build(): Hateoas } }); + $this->serializerBuilder->addMetadataDirs($this->metadataDirs); + $this->serializerBuilder->setExpressionEvaluator($this->expressionEvaluator); + $jmsSerializer = $this->serializerBuilder->build(); return new Hateoas($jmsSerializer, $linkHelper); diff --git a/tests/Hateoas/Tests/Fixtures/NoAnnotations.php b/tests/Hateoas/Tests/Fixtures/NoAnnotations.php new file mode 100644 index 00000000..19ab8e78 --- /dev/null +++ b/tests/Hateoas/Tests/Fixtures/NoAnnotations.php @@ -0,0 +1,28 @@ +id = $id; + $this->number = $number; + } + + public function id(): string + { + return $this->id; + } + + public function number(): int + { + return $this->number; + } +} diff --git a/tests/Hateoas/Tests/Fixtures/config/Hateoas.Tests.Fixtures.NoAnnotations.xml b/tests/Hateoas/Tests/Fixtures/config/Hateoas.Tests.Fixtures.NoAnnotations.xml new file mode 100644 index 00000000..df94b75b --- /dev/null +++ b/tests/Hateoas/Tests/Fixtures/config/Hateoas.Tests.Fixtures.NoAnnotations.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/tests/Hateoas/Tests/HateoasBuilderTest.php b/tests/Hateoas/Tests/HateoasBuilderTest.php index 953584dd..c5b9dcfe 100644 --- a/tests/Hateoas/Tests/HateoasBuilderTest.php +++ b/tests/Hateoas/Tests/HateoasBuilderTest.php @@ -8,6 +8,7 @@ use Hateoas\Tests\Fixtures\AdrienBrault; use Hateoas\Tests\Fixtures\CircularReference1; use Hateoas\Tests\Fixtures\CircularReference2; +use Hateoas\Tests\Fixtures\NoAnnotations; use Hateoas\Tests\Fixtures\WithAlternativeRouter; use Hateoas\UrlGenerator\CallableUrlGenerator; use JMS\Serializer\SerializationContext; @@ -160,4 +161,27 @@ public function testWithNullInEmbedded() $hateoas->serialize($reference1, 'json', SerializationContext::create()->setSerializeNull(true)) ); } + + public function testWithXmlRootNameFromXmlConfiguration() + { + $hateoas = HateoasBuilder::create() + ->addMetadataDir(self::rootPath() . '/Fixtures/config') + ->build(); + + $resource = new NoAnnotations('#303', 303); + + $this->assertSame( + << + + + 303 + + + +XML + , + $hateoas->serialize($resource, 'xml') + ); + } }