/** * Asserts that the provided type is a valid collection type for JAX-RS resource parameters. * * @param paramType * the provided type. * @param paramName * the name of the resource parameter for error reporting. * @param jaxrsParamType * the JAX-RS resource parameter type for error reporting. * * @return the element type. * @throws GenerationException * if the type parameters of the collection type are invalid for JAX-RS resource * parameters. */ private MetaClass assertValidCollectionParam(final MetaClass paramType, final String paramName, final Class<?> jaxrsParamType) { final MetaParameterizedType queryParamPType = paramType.getParameterizedType(); final MetaType[] typeParams = (queryParamPType != null) ? queryParamPType.getTypeParameters() : null; if (typeParams != null && typeParams.length == 1 && typeParams[0] instanceof MetaClass && PrimitiveTypeMarshaller.canHandle((MetaClass) typeParams[0], "text/plain")) { return (MetaClass) typeParams[0]; } else { throw new GenerationException( "Unsupported type parameter found on " + jaxrsParamType.getSimpleName() + " with name " + paramName + " in method " + resourceMethod.getMethod() + " (check the JavaDocs of " + jaxrsParamType.getName() + " for details!)"); } }
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; }
public static Statement marshal(final MetaClass type, final Statement statement, final String contentType) { Statement marshallingStatement = null; if (PrimitiveTypeMarshaller.canHandle(type, contentType)) { marshallingStatement = PrimitiveTypeMarshaller.marshal(type, statement); } else { marshallingStatement = Stmt.invokeStatic(MarshallingWrapper.class, "toJSON", statement); } return marshallingStatement; }