Order of JSONArray not kept

0
I am parsing a JSON Array and creating MendixObjectReferenceSet    JSONArray srcJsonArray;     for(int i = 0; i < srcJsonArray.length(); i++)     {             Object jsonElement = srcJsonArray.get(i);             IMendixObject elmentEntity = Core.instantiate(context, elementType);             // Set values on elmentEntity                           MendixObjectReference reference =  (MendixObjectReference)elmentEntity.getMember(context,memberName);          reference.setValue(context, tgtEntity.getId());                 }   However when I later retrieve those array elements from the reference set, the order is not preserved from the JSONArray order.         List<IMendixObject> arrayObjs = Core.retrieveByPath(context, tgtEntity, memberName, true);   Is there a way to preserve the order as defined by the source JSON Array?  
asked
2 answers
0

The order in a referenceset is not guaranteed. If you need the order as you input the data use a reference instead.

answered
0

At least in 9.24.2, the order is preserved when parsing JSON array with import mapping. The reason is "Retrieve by path" action/Core.retrieveByPath() returns a list sorted by IMendixIdentifier and for objects of the same type created on the same app instance IMendixIdentifier is monotonic.

 

answered