/** * Returns the element type of the given metaclass under the following conditions: * <ul> * <li>toType is a collection type * <li>toType has a single type parameter * <li>toType's type parameter is not a wildcard * <li>toType's type parameter is a non-abstract (concrete) type * <li>toType's type parameter is not java.lang.Object * </ul> * * @param toType * The type to check for a known concrete collection element type. * @return The concrete element type meeting all above-mentioned criteria, or null if one or more * of the criteria fails. */ public static MetaClass getConcreteCollectionElementType(final MetaClass toType) { if (toType.isAssignableTo(Collection.class)) { return getConcreteElementType(toType); } return null; }
/** * Returns the element type of the given metaclass under the following conditions: * <ul> * <li>toType is a collection type * <li>toType has a single type parameter * <li>toType's type parameter is not a wildcard * <li>toType's type parameter is a non-abstract (concrete) type * <li>toType's type parameter is not java.lang.Object * </ul> * * @param toType * The type to check for a known concrete collection element type. * @return The concrete element type meeting all above-mentioned criteria, or null if one or more * of the criteria fails. */ public static MetaClass getConcreteCollectionElementType(final MetaClass toType) { if (toType.isAssignableTo(Collection.class)) { return getConcreteElementType(toType); } return null; }
public static Statement demarshal(final MetaClass type, final Statement statement, final String accepts) { Statement demarshallingStatement = null; if (PrimitiveTypeMarshaller.canHandle(type, accepts)) { demarshallingStatement = PrimitiveTypeMarshaller.demarshal(type, statement); } else { if (!type.equals(MetaClassFactory.get(void.class))) { if (type.isAssignableTo(Map.class)) { demarshallingStatement = Stmt.invokeStatic(MarshallingWrapper.class, "fromJSON", statement, type.asBoxed().asClass(), MarshallingGenUtil.getConcreteMapKeyType(type.asBoxed()), MarshallingGenUtil.getConcreteMapValueType(type.asBoxed())); } else { demarshallingStatement = Stmt.invokeStatic(MarshallingWrapper.class, "fromJSON", statement, type.asBoxed().asClass(), MarshallingGenUtil.getConcreteElementType(type.asBoxed())); } } else { demarshallingStatement = Stmt.invokeStatic(MarshallingWrapper.class, "fromJSON", statement); } } return demarshallingStatement; }