@@ -593,38 +593,38 @@ private function processObject($data, Context $options, $path, $result = null)
593593
594594 if ($ this ->useObjectAsArray ) {
595595 $ result = array ();
596- } else /*if (!$result instanceof ObjectItemContract || null !== $this->objectItemClass)*/ {
596+ } else {
597597 //* todo check performance impact
598598 if (null === $ this ->objectItemClass ) {
599- $ result = new ObjectItem ();
599+ if (!$ result instanceof ObjectItemContract) {
600+ $ result = new ObjectItem ();
601+ $ result ->setDocumentPath ($ path );
602+ }
600603 } else {
601604 $ className = $ this ->objectItemClass ;
602605 if ($ options ->objectItemClassMapping !== null ) {
603606 if (isset ($ options ->objectItemClassMapping [$ className ])) {
604607 $ className = $ options ->objectItemClassMapping [$ className ];
605608 }
606609 }
607- $ result = new $ className ;
608- }
609- //*/
610-
611-
612- if ($ result instanceof ClassStructure) {
613- if ($ result ->__validateOnSet ) {
614- $ result ->__validateOnSet = false ;
615- /** @noinspection PhpUnusedLocalVariableInspection */
616- /* todo check performance impact
617- $validateOnSetHandler = new ScopeExit(function () use ($result) {
618- $result->__validateOnSet = true;
619- });
610+ if (null !== $ result && get_class ($ result ) !== $ className ) {
611+ $ result = new $ className ;
612+ //* todo check performance impact
613+ if ($ result instanceof ClassStructure) {
614+ $ result ->setDocumentPath ($ path );
615+ if ($ result ->__validateOnSet ) {
616+ $ result ->__validateOnSet = false ;
617+ /** @noinspection PhpUnusedLocalVariableInspection */
618+ /* todo check performance impact
619+ $validateOnSetHandler = new ScopeExit(function () use ($result) {
620+ $result->__validateOnSet = true;
621+ });
622+ //*/
623+ }
624+ }
620625 //*/
621626 }
622627 }
623-
624- //* todo check performance impact
625- if ($ result instanceof ObjectItemContract) {
626- $ result ->setDocumentPath ($ path );
627- }
628628 //*/
629629 }
630630 }
0 commit comments