diff --git a/src/JsonSerializerTrait.php b/src/JsonSerializerTrait.php index e4ca11f..0436f36 100644 --- a/src/JsonSerializerTrait.php +++ b/src/JsonSerializerTrait.php @@ -16,9 +16,6 @@ trait JsonSerializerTrait public function serialize(object $obj): array { $class = new ReflectionClass($obj); - if ($class->isEnum()) { - return $obj->value; - } $skipAttributeCheck = ($class->getAttributes(JsonObjectAttribute::class)[0] ?? null) !== null; $output = []; diff --git a/tests/SerializerTest.php b/tests/SerializerTest.php index eebe667..2b4a3a3 100644 --- a/tests/SerializerTest.php +++ b/tests/SerializerTest.php @@ -136,6 +136,34 @@ public function testArrayEnum(): void JsonHandler::Encode($arr); } + /** + * @throws JsonException + * @throws ReflectionException + */ + public function testArrayOfChild(): void + { + $obj = new WithArrayOfChildObject(); + + $handler = new JsonHandler(); + $arr = $handler->serialize($obj); + + $this->assertArrayHasKey('id', $arr); + $this->assertArrayHasKey('children', $arr); + $this->assertIsArray($arr['children']); + $this->assertCount(2, $arr['children']); + $this->assertIsArray($arr['children'][0]); + + $this->assertArrayHasKey('string', $arr['children'][1]); + $this->assertArrayHasKey('int', $arr['children'][1]); + $this->assertIsInt($arr['children'][1]['int']); + $this->assertEquals(11, $arr['children'][1]['int']); + + $this->assertIsFloat($arr['children'][1]['float']); + $this->assertEquals(11.50, $arr['children'][1]['float']); + + JsonHandler::Encode($arr); + } + /** * @throws JsonException * @throws ReflectionException