@@ -161,8 +161,10 @@ private function convertJsonArray($entityObject, $jsonArrayMetadata)
161
161
162
162
foreach ($ jsonArrayMetadata as $ jsonElement ) {
163
163
if ($ jsonElement ->getType () == JsonObjectExtractor::JSON_OBJECT_OBJ_NAME ) {
164
+ $ entityObj = $ this ->resolveJsonObjectAndEntityData ($ entityObject , $ jsonElement ->getValue ());
164
165
$ jsonArray [$ jsonElement ->getValue ()] =
165
- $ this ->convertJsonArray ($ entityObject , $ jsonElement ->getNestedMetadata ());
166
+ $ this ->convertJsonArray ($ entityObj , $ jsonElement ->getNestedMetadata ());
167
+ continue ;
166
168
}
167
169
168
170
$ jsonElementType = $ jsonElement ->getValue ();
@@ -222,6 +224,25 @@ private function convertJsonArray($entityObject, $jsonArrayMetadata)
222
224
return $ jsonArray ;
223
225
}
224
226
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
+
225
246
/**
226
247
* Resolves JsonObjects and pre-defined metadata (in other operation.xml file) referenced by the json metadata
227
248
*
@@ -233,6 +254,7 @@ private function resolveNonPrimitiveElement($entityName, $jsonElement)
233
254
{
234
255
$ linkedEntityObj = $ this ->resolveLinkedEntityObject ($ entityName );
235
256
257
+ // in array case
236
258
if (!empty ($ jsonElement ->getNestedJsonElement ($ jsonElement ->getValue ()))
237
259
&& $ jsonElement ->getType () == 'array '
238
260
) {
0 commit comments