Search in sources :

Example 1 with ArrayType

use of weborb.reader.ArrayType in project Android-SDK by Backendless.

the class CollectionAdaptingPolicy method adapt.

@Override
public Object adapt(Class<E> clazz, IAdaptingType entity, IResponder nextResponder) {
    List<E> result = null;
    try {
        List<E> list = new ArrayList<>();
        if (entity == null)
            return list;
        ArrayType data = (ArrayType) entity;
        Object[] dataArray = (Object[]) data.getArray();
        if (clazz != null && weborb.types.Types.getMappedClientClass(clazz.getName()) == null) {
            for (Object aDataArray : dataArray) if (aDataArray instanceof NamedObject)
                ((NamedObject) aDataArray).setDefaultType(clazz);
        }
        result = (List<E>) entity.adapt(list.getClass());
        if (nextResponder != null)
            nextResponder.responseHandler(result);
    } catch (AdaptingException e) {
        Fault fault = new Fault("Unable to adapt response to List<" + clazz.getName() + ">", e.getMessage());
        if (nextResponder != null)
            nextResponder.errorHandler(fault);
    }
    return result;
}
Also used : ArrayType(weborb.reader.ArrayType) ArrayList(java.util.ArrayList) NamedObject(weborb.reader.NamedObject) AdaptingException(weborb.exceptions.AdaptingException) NamedObject(weborb.reader.NamedObject) Fault(weborb.client.Fault)

Aggregations

ArrayList (java.util.ArrayList)1 Fault (weborb.client.Fault)1 AdaptingException (weborb.exceptions.AdaptingException)1 ArrayType (weborb.reader.ArrayType)1 NamedObject (weborb.reader.NamedObject)1