@@ -161,8 +161,10 @@ private function convertJsonArray($entityObject, $jsonArrayMetadata)
161161
162162 foreach ($ jsonArrayMetadata as $ jsonElement ) {
163163 if ($ jsonElement ->getType () == JsonObjectExtractor::JSON_OBJECT_OBJ_NAME ) {
164+ $ entityObj = $ this ->resolveJsonObjectAndEntityData ($ entityObject , $ jsonElement ->getValue ());
164165 $ jsonArray [$ jsonElement ->getValue ()] =
165- $ this ->convertJsonArray ($ entityObject , $ jsonElement ->getNestedMetadata ());
166+ $ this ->convertJsonArray ($ entityObj , $ jsonElement ->getNestedMetadata ());
167+ continue ;
166168 }
167169
168170 $ jsonElementType = $ jsonElement ->getValue ();
@@ -222,6 +224,25 @@ private function convertJsonArray($entityObject, $jsonArrayMetadata)
222224 return $ jsonArray ;
223225 }
224226
227+ /**
228+ * This function does a comparison of the entity object being matched to the json element. If there is a mismatch in
229+ * type we attempt to use a nested entity, if the entities are properly matched, we simply return the object.
230+ *
231+ * @param EntityDataObject $entityObject
232+ * @param string $jsonElementValue
233+ * @return EntityDataObject|null
234+ */
235+ private function resolveJsonObjectAndEntityData ($ entityObject , $ jsonElementValue )
236+ {
237+ if ($ jsonElementValue != $ entityObject ->getType ()) {
238+ // if we have a mismatch attempt to retrieve linked data and return just the first linkage
239+ $ linkName = $ entityObject ->getLinkedEntitiesOfType ($ jsonElementValue )[0 ];
240+ return DataObjectHandler::getInstance ()->getObject ($ linkName );
241+ }
242+
243+ return $ entityObject ;
244+ }
245+
225246 /**
226247 * Resolves JsonObjects and pre-defined metadata (in other operation.xml file) referenced by the json metadata
227248 *
@@ -233,6 +254,7 @@ private function resolveNonPrimitiveElement($entityName, $jsonElement)
233254 {
234255 $ linkedEntityObj = $ this ->resolveLinkedEntityObject ($ entityName );
235256
257+ // in array case
236258 if (!empty ($ jsonElement ->getNestedJsonElement ($ jsonElement ->getValue ()))
237259 && $ jsonElement ->getType () == 'array '
238260 ) {
0 commit comments