public static Object convert(String value, ResolvedType type) { if (type.isInstanceOf(Short.class) || type.isInstanceOf(Short.TYPE)) { return Short.parseShort(value); } else if (type.isInstanceOf(Integer.class) || type.isInstanceOf(Integer.TYPE)) { return Integer.parseInt(value); } else if (type.isInstanceOf(Long.class) || type.isInstanceOf(Long.TYPE)) { return Long.parseLong(value); } else if (type.isInstanceOf(Float.class) || type.isInstanceOf(Float.TYPE)) { return Float.parseFloat(value); } else if (type.isInstanceOf(Double.class) || type.isInstanceOf(Double.TYPE)) { return Double.parseDouble(value); } else if (type.isInstanceOf(Boolean.class) || type.isInstanceOf(Boolean.TYPE)) { return Boolean.parseBoolean(value); } else if (type.isInstanceOf(List.class)) { ResolvedType itemType = type.typeParametersFor(List.class).get(0); return StreamSupport.stream(Splitter.on(',').split(value).spliterator(), false).map(item -> convert(item, itemType)).collect(Collectors.toList()); } else { return value; } }
@Override public Iterable<? extends ModelProperty> propertiesForSerialization(ResolvedType type) { List<ModelProperty> serializableProperties = newArrayList(); Iterables.addAll(serializableProperties,defaultModelPropertiesProvider.propertiesForSerialization(type)); if(type.isInstanceOf(scala.Product.class)){ //special case for Scala Case Classes. fields are defined in the constructor addConstructors(serializableProperties, type); } return serializableProperties; }
private Object resolvParam(NamedDefaultedRestParam param, List<String> values, ResolvedType resolvedType) { if (param.getType().isInstanceOf(List.class) && values.size() != 1) { ResolvedType itemType = param.getType().typeParametersFor(List.class).get(0); return values.stream().map(value -> RestParam.convert(value, itemType)).collect(Collectors.toList()); } else { return RestParam.convert(Iterables.getFirst(values, null), resolvedType); } }
static ResultReturnThing forType(ResolvedMethod method) { ResolvedType return_type = method.getReturnType(); if (return_type == null) { throw new IllegalStateException(String.format( "Method %s#%s is annotated as if it should return a value, but the method is void.", method.getDeclaringType().getErasedType().getName(), method.getName())); } else if (return_type.isInstanceOf(ResultBearing.class)) { return new ResultBearingResultReturnThing(method); } else if (return_type.isInstanceOf(Iterable.class)) { return new IterableReturningThing(method); } else if (return_type.isInstanceOf(Iterator.class)) { return new IteratorResultReturnThing(method); } else { return new SingleValueResultReturnThing(method); } }
CallHandler(Class<?> sqlObjectType, ResolvedMethod method) { super(sqlObjectType, method); if (null != method.getReturnType() ) { if (method.getReturnType().isInstanceOf(OutParameters.class)){ returnOutParams = true; } else { throw new IllegalArgumentException("@SqlCall methods may only return null or OutParameters at present"); } } else { returnOutParams = false; } this.sql = SqlObject.getSql(method.getRawMember().getAnnotation(SqlCall.class), method.getRawMember()); }
for (int argIndex = 0; argIndex < parameterAnnotations.length; argIndex++) { ResolvedType resolvedType = new TypeResolver().resolve(parametersTypes[argIndex]); if (resolvedType.isInstanceOf(APIContext.class)) { contexArgIndex = argIndex; } else if (processPathParam(parameterAnnotations[argIndex],resolvedType,argumentIndexToRestParam,argIndex)) {