package org.restler.spring.data.proxy;

import org.restler.client.Call;
import org.restler.client.CallEnhancer;
import org.restler.client.CallExecutionChain;
import org.restler.client.CallExecutor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ProxyCallEnhancer implements CallEnhancer {
    @Override
    public Object apply(Call call, CallExecutor callExecutor) {
        Object object = callExecutor.execute(call);

        if(object instanceof Collection) {
            Collection<Object> collection = (Collection<Object>)object;

            for(Object item : collection) {
                initProxyObject(item, callExecutor);
            }

        } else {
            initProxyObject(object, callExecutor);
        }


        return object;
    }

    private void initProxyObject(Object object, CallExecutor callExecutor) {
        if(object instanceof ResourceProxy) {
            List<CallEnhancer> proxyEnhancer = new ArrayList<>();
            proxyEnhancer.add(this);
            CallExecutionChain chain = new CallExecutionChain(callExecutor, proxyEnhancer);
            ResourceProxy resourceProxy = (ResourceProxy)object;
            resourceProxy.setExecutor(chain);
        }
    }


}

@@ -271,16 +271,42 @@
 il.List;
+%0Aimport java.util.Objects;
 %0A%0Apublic
@@ -516,16 +516,218 @@
 tanceof 
+Object%5B%5D) %7B%0A            Object%5B%5D array = (Object%5B%5D)object;%0A%0A            for(Object item : array) %7B%0A                initProxyObject(item, callExecutor);%0A            %7D%0A        %7D else if(object instanceof 
 Collecti

Add support arrays.