diff --git a/src/lib/Output/Generator/Json/FieldTypeHashGenerator.php b/src/lib/Output/Generator/Json/FieldTypeHashGenerator.php index 81f337a2..89af196d 100644 --- a/src/lib/Output/Generator/Json/FieldTypeHashGenerator.php +++ b/src/lib/Output/Generator/Json/FieldTypeHashGenerator.php @@ -166,7 +166,11 @@ private function generateObjectValue($parent, object $value) $value = null; } - return $this->generateValue($parent, $value); + if (is_array($value)) { + return $this->generateArrayValue($parent, $value); + } + + return $value; } } diff --git a/src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php b/src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php index 739a2d3c..c3fcaf95 100644 --- a/src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php +++ b/src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php @@ -255,6 +255,13 @@ private function generateObjectValue(object $value, \XmlWriter $writer, ?string ]); $value = null; } + + if (is_object($value)) { + $this->generateNullValue($writer, $key, $elementName); + + return; + } + $this->generateValue($writer, $value, $key, $elementName); } } diff --git a/tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php b/tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php index 8d71ca8d..79c03596 100644 --- a/tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php +++ b/tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php @@ -219,6 +219,20 @@ public function testGenerateUsingNormalizer(): void $this->assertSerializationSame(__FUNCTION__); } + public function testGenerateObjectUsingNormalizer(): void + { + $object = (object)[]; + $this->getNormalizer() + ->expects(self::once()) + ->method('normalize') + ->with(self::identicalTo($object)) + ->willReturnArgument(0); + + $this->getGenerator()->generateFieldTypeHash('fieldValue', $object); + + $this->assertSerializationSame(__FUNCTION__); + } + public function testGenerateWithMissingNormalizer(): void { $object = (object)[]; diff --git a/tests/lib/Output/Generator/_fixtures/Json_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out b/tests/lib/Output/Generator/_fixtures/Json_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out new file mode 100644 index 00000000..024c4fdf --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/Json_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out @@ -0,0 +1 @@ +{"Field":{"fieldValue":{}}} \ No newline at end of file diff --git a/tests/lib/Output/Generator/_fixtures/Xml_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out b/tests/lib/Output/Generator/_fixtures/Xml_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out new file mode 100644 index 00000000..40d692ad --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/Xml_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out @@ -0,0 +1,4 @@ + + + +