private static Map < CharSequence , Object > getInitialIdToObjectMap ( final Object objectInstance , final Object parsedJSON ) { final Map < CharSequence , Object > idToObjectInstance = new HashMap <> ( ) ; if ( parsedJSON instanceof JSONObject ) { final JSONObject itemJsonObject = ( JSONObject ) parsedJSON ; if ( ! itemJsonObject . items . isEmpty ( ) ) { final Entry < String , Object > firstItem = itemJsonObject . items . get ( 0 ) ; if ( firstItem . getKey ( ) . equals ( JSONUtils . ID_KEY ) ) { final Object firstItemValue = firstItem . getValue ( ) ; if ( firstItemValue == null || ! CharSequence . class . isAssignableFrom ( firstItemValue . getClass ( ) ) ) { idToObjectInstance . put ( ( CharSequence ) firstItemValue , objectInstance ) ; } } } } return idToObjectInstance ; }
Set up the initial mapping from id to object by adding the id of the toplevel object if it has an id field in JSON .