Marshal collection.

@param cassandraTypeClazz
the cassandra type clazz
@param result
the result
@param clazz
the clazz
@return the collection
1879
public static Collection marshalCollection(Class cassandraTypeClazz, Collection result, Class clazz, Class resultTypeClass)
    {
        Collection mappedCollection = result;

        if (cassandraTypeClazz.isAssignableFrom(BytesType.class))
        {
            mappedCollection = (Collection) PropertyAccessorHelper.getObject(resultTypeClass);
            for (Object value : result)
            {
                byte[] valueAsBytes = new byte[((ByteBuffer) value).remaining()];
                ((ByteBuffer) value).get(valueAsBytes);
                 mappedCollection.add(PropertyAccessorHelper.getObject(clazz, valueAsBytes));
            }
        }
        return mappedCollection;
    }
204610
public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
		if (collection == null) {
			return null;
		}
		return collection.toArray(new Class<?>[collection.size()]);
	}
873790
@SuppressWarnings("unchecked")
    public static <T> T fromByteArrayKryo(byte[] data, Class<T> clazz, ClassLoader classLoader) {
        if (data == null) {
            return null;
        }
        Kryo kryo = kryoPool.obtain();
        try {
            ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
            if (classLoader != null) {
                Thread.currentThread().setContextClassLoader(classLoader);
            }
            try {
                Input input = kryoInputPool.obtain();
                try {
                    kryo.setClassLoader(classLoader != null ? classLoader : oldClassLoader);
                    input.setInputStream(new ByteArrayInputStream(data));
                    Object obj = kryo.readClassAndObject(input);
                    input.close();
                    return obj != null && clazz.isAssignableFrom(obj.getClass()) ? (T) obj : null;
                } finally {
                    kryoInputPool.free(input);
                }
            } finally {
                Thread.currentThread().setContextClassLoader(oldClassLoader);
            }
        } finally {
            kryoPool.free(kryo);
        }
    }
1228311
@NotNull
    public final String marshal(@NotNull final SerializerRegistry registry, 
            @NotNull final CommonEvent commonEvent) {

        Contract.requireArgNotNull("registry", registry);
        Contract.requireArgNotNull("commonEvent", commonEvent);

        final Serializer serializer = registry.getSerializer(EscEvent.SER_TYPE);

        final EscEvent event = createEscEvent(registry, serializer.getMimeType(), commonEvent);
        final byte[] data = serializer.marshal(event, EscEvent.SER_TYPE);
        return new String(data, serializer.getMimeType().getEncoding());
    }
298362
public static ResultDescriptor analyzeReturnType(final DescriptorContext context,
                                                     final Class<? extends Collection> returnCollectionType) {
        final Method method = context.method;
        final MethodGenericsContext generics = context.generics.method(method);
        final Class<?> returnClass = generics.resolveReturnClass();
        final ResultDescriptor descriptor = new ResultDescriptor();
        descriptor.expectType = resolveExpectedType(returnClass, returnCollectionType);

        final ResultType type;
        final Class<?> entityClass;
        if (isCollection(returnClass)) {
            type = COLLECTION;
            entityClass = resolveGenericType(method, generics);
        } else if (returnClass.isArray()) {
            type = ARRAY;
            entityClass = returnClass.getComponentType();
        } else if (VOID_TYPES.contains(returnClass)) {
            type = VOID;
            entityClass = Void.class;
        } else {
            type = PLAIN;
            // support for guava and jdk8 optionals
            entityClass = Optionals.isOptional(returnClass)
                    ? resolveGenericType(method, generics) : returnClass;
        }
        descriptor.returnType = type;
        descriptor.entityType = entityClass;
        return descriptor;
    }
419051
public static <T> T deserializeByType(Object src, Class<T> clazz) {
        if (src == null) {
            return (T) ClassUtils.getDefaultPrimitiveValue(clazz);
        } else if (src instanceof Boolean) {
            return (T) CompatibleTypeUtils.convert(src, clazz);
        } else if (src instanceof Number) {
            return (T) CompatibleTypeUtils.convert(src, clazz);
        } else if (src instanceof Map) { // map-->可能是map或者自定义对象
            Map srcMap = (Map) src;
            if (clazz == Object.class) { // 需要自省
                if (srcMap.containsKey(JSON.CLASS_KEY)) {
                    return (T) mapToObject(srcMap, Object.class); // 自定义对象
                } else {
                    return (T) mapToMap(srcMap, srcMap.getClass());
                }
            } else {
                if (Map.class.isAssignableFrom(clazz)) { // map转map
                    return (T) mapToMap(srcMap, (Class<? extends Map>) clazz);
                } else {
                    return mapToObject(srcMap, clazz); // 自定义对象
                }
            }
        } else if (src instanceof Collection) {
            Collection list = (Collection) src;
            if (clazz == Object.class) {
                return (T) collection2Collection(list, list.getClass(), Object.class);
            } else if (Collection.class.isAssignableFrom(clazz)) {
                return (T) collection2Collection(list, (Class<? extends Collection>) clazz, Object.class);
            } else if (clazz.isArray()) {
                if (clazz.getComponentType().isPrimitive()) {
                    return (T) CompatibleTypeUtils.convert(list, clazz);
                } else {
                    return (T) collectionToArray(list, clazz.getComponentType());
                }
            } else {
                return (T) list;
            }
        } else if (src.getClass().isArray()) {
            Class componentType = src.getClass().getComponentType();
            if (componentType.isPrimitive()) {
                if (Collection.class.isAssignableFrom(clazz)) {
                    return (T) arrayToCollection(src, (Class<? extends Collection>) clazz, Object.class);
                } else {
                    return (T) src;
                }
            } else {
                Object[] array = (Object[]) src;
                if (clazz == Object.class) {
                    return (T) array2Array(array, array.getClass().getComponentType());
                } else if (clazz.isArray()) {
                    return (T) array2Array(array, clazz.getComponentType());
                } else if (Collection.class.isAssignableFrom(clazz)) {
                    return (T) arrayToCollection(src, (Class<? extends Collection>) clazz, Object.class);
                } else {
                    return (T) src;
                }
            }
        } else if (clazz.isEnum()) { // 枚举 从字符串进行读取
            if (src instanceof String) {
                return (T) Enum.valueOf((Class<? extends Enum>) clazz, (String) src);
            } else {
                throw new RuntimeException("Enum field must set string!");
            }
        } else if (Date.class.isAssignableFrom(clazz)) { // 日期：支持long和标准格式字符串
            if (src instanceof Long) {
                return (T) new Date((Long) src);
            } else if (src instanceof String) {
                try {
                    return (T) DateUtils.strToDate((String) src);
                } catch (Exception e) {
                    throw new RuntimeException("Date field must set string(yyyy-MM-dd HH:mm:ss)!");
                }
            } else {
                throw new RuntimeException("Date field must set long or string(yyyy-MM-dd HH:mm:ss)!");
            }
        } else if (src instanceof String) { // 字符串支持转换
            return (T) CompatibleTypeUtils.convert(src, clazz);
        } else { // 其它返回src
            return (T) src;
        }
    }
990316
<T> Collection<Method> getPrimaryKeyGetters(Class<T> clazz) {
        synchronized (primaryKeyGettersCache) {
            if ( !primaryKeyGettersCache.containsKey(clazz) ) {
                List<Method> keyGetters = new LinkedList<Method>();
                for (Method getter : getRelevantGetters(clazz)) {
                    if (ReflectionUtils.getterOrFieldHasAnnotation(getter, DynamoDBHashKey.class)
                        || ReflectionUtils.getterOrFieldHasAnnotation(getter, DynamoDBRangeKey.class)) {
                        keyGetters.add(getter);
                    }
                }
                primaryKeyGettersCache.put(clazz, keyGetters);
            }
            return primaryKeyGettersCache.get(clazz);
        }
    }
632957
private static <T extends Annotation, R> Builder<R> getAnnotatedInstances(
            AnnotatedElement method, AnnotatedElement clazz, Class<T> annotationType, Class<R> resultType) {
        final Builder<R> builder = new Builder<>();
        Stream.concat(findAll(method, annotationType).stream(),
                      findAll(clazz, annotationType).stream())
              .forEach(annotation -> builder.add(getInstance(annotation, resultType)));
        return builder;
    }
1206106
public static CassandraType getCassandraDataTypeClass(Class clazz)
    {
        if(clazz.isEnum()){
            return CassandraType.STRING;
        }
        return typeToClazz.get(clazz);
    }
1192672
public <T> T[] asArray(Class<T> clazz) {
      return Cast.as(convert(toConvert, Array.newInstance(clazz, 0).getClass()));
   }
1122282
@Override
    public void marshal(Object graph, Result result) throws IOException, XmlMappingException {
        @SuppressWarnings("unchecked")
        final Tuple<String, Element> data = (Tuple<String, Element>) graph;

        final Transformer transformer;
        try {
            transformer = this.xmlUtilities.getIdentityTransformer();
        } catch (TransformerConfigurationException e) {
            throw new RuntimeException("Failed to load identity Transformer", e);
        }

        // Setup the transformer to pretty-print the output
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

        try {
            transformer.transform(new DocumentSource(data.second), result);
        } catch (TransformerException e) {
            throw new RuntimeException("Failed to write Element to Result for: " + data.first, e);
        }
    }
337426
private List<?> toList(Object results)
    {
        if (results instanceof Object[])
        {
            return Arrays.asList( (Object[]) results );
        }
        if (results instanceof Collection)
        {
            return new ArrayList<Object>( (Collection<?>) results );
        }
        return null;
    }
475797
@SuppressWarnings("PMD.LooseCoupling")
    public static Object convertToArray(final Object result, final Class entityType, final boolean projection) {
        final Collection res = result instanceof Collection
                // no projection because its applied later
                ? (Collection) result : convertToCollectionImpl(result, ArrayList.class, entityType, false);
        final Object array = Array.newInstance(entityType, res.size());
        int i = 0;
        for (Object obj : res) {
            Array.set(array, i++, projection ? applyProjection(obj, entityType) : obj);
        }
        return array;
    }
1295648
ModuleMarshal marshal(Class<?> sourceType)
  {
    ModuleMarshal marshal = _marshalSourceMap.get(sourceType);
    
    if (marshal == null) {
      marshal = marshalImpl(sourceType);
      _marshalSourceMap.put(sourceType, marshal);
    }
    
    return marshal;
  }
1332513
@EachBean(Cluster.Builder.class)
    @Bean(preDestroy = "close")
    public Cluster cassandraCluster(Cluster.Builder builder) {
        return builder.build();
    }
470225
@SuppressWarnings("unchecked")
	public <P extends ParaObject> List<P> getItemsFromList(List<?> result) {
		if (result != null && !result.isEmpty()) {
			// this isn't very efficient but there's no way to know what type of objects we're reading
			ArrayList<P> objects = new ArrayList<>(result.size());
			for (Object map : result) {
				P p = ParaObjectUtils.setAnnotatedFields((Map<String, Object>) map);
				if (p != null) {
					objects.add(p);
				}
			}
			return objects;
		}
		return Collections.emptyList();
	}
218082
public Marshaller createMarshaller(Class<?> clazz) throws JAXBException {
    Marshaller marshaller = getContext(clazz).createMarshaller();
    setMarshallerProperties(marshaller);
    return marshaller;
  }