diff --git a/src/JMS/Serializer/Metadata/Driver/YamlDriver.php b/src/JMS/Serializer/Metadata/Driver/YamlDriver.php index 376bb398d..182032456 100644 --- a/src/JMS/Serializer/Metadata/Driver/YamlDriver.php +++ b/src/JMS/Serializer/Metadata/Driver/YamlDriver.php @@ -224,6 +224,10 @@ protected function getExtension() private function addClassProperties(ClassMetadata $metadata, array $config) { + if (isset($config['custom_accessor_order']) && ! isset($config['accessor_order'])) { + $config['accessor_order'] = 'custom'; + } + if (isset($config['accessor_order'])) { $metadata->setAccessorOrder($config['accessor_order'], isset($config['custom_accessor_order']) ? $config['custom_accessor_order'] : array()); } diff --git a/tests/JMS/Serializer/Tests/Metadata/Driver/YamlDriverTest.php b/tests/JMS/Serializer/Tests/Metadata/Driver/YamlDriverTest.php index 94194f5f4..a4aa8b4a8 100644 --- a/tests/JMS/Serializer/Tests/Metadata/Driver/YamlDriverTest.php +++ b/tests/JMS/Serializer/Tests/Metadata/Driver/YamlDriverTest.php @@ -24,6 +24,12 @@ class YamlDriverTest extends BaseDriverTest { + public function testAccessorOrderIsInferred() + { + $m = $this->getDriverForSubDir('accessor_inferred')->loadMetadataForClass(new \ReflectionClass('JMS\Serializer\Tests\Fixtures\Person')); + $this->assertEquals(array('age', 'name'), array_keys($m->propertyMetadata)); + } + public function testShortExposeSyntax() { $m = $this->getDriverForSubDir('short_expose')->loadMetadataForClass(new \ReflectionClass('JMS\Serializer\Tests\Fixtures\Person')); diff --git a/tests/JMS/Serializer/Tests/Metadata/Driver/yml/accessor_inferred/Person.yml b/tests/JMS/Serializer/Tests/Metadata/Driver/yml/accessor_inferred/Person.yml new file mode 100644 index 000000000..933e03fc3 --- /dev/null +++ b/tests/JMS/Serializer/Tests/Metadata/Driver/yml/accessor_inferred/Person.yml @@ -0,0 +1,6 @@ +JMS\Serializer\Tests\Fixtures\Person: + custom_accessor_order: ["age", "name"] + + properties: + age: ~ + name: ~