@Test(expected = ConversionFailedException.class) public void testTointException() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("intParam", Integer.TYPE); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.invocableHandlerMethod.convert(param, "str")).isEqualTo("str"); }
@Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers(
			HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer(
			ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments,
			Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument); }
InvocableHandlerMethod extends HandlerMethod { @Nullable public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().equals(Optional.class)) { return Optional.empty(); } return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.getElementTypeDescriptor() != null) { if (td.isCollection()) { JavaType elemType = typeFactory .constructType(td.getElementTypeDescriptor().getType()); TypeVariable<?>[] vars = targetClass.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { bindings = TypeBindings.emptyBindings(); } else { bindings = TypeBindings.create(targetClass, elemType); } JavaType superClass = null; Class<?> parent = targetClass.getSuperclass(); if (parent != null) { superClass = TypeFactory.unknownType(); } JavaType type = CollectionType.construct(targetClass, bindings, superClass, null, elemType); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType( td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } } throw e; } } return this.objectMapper.convertValue(argument, targetClass); } InvocableHandlerMethod(HandlerMethod handlerMethod); void setArgumentResolvers(
			HandlerMethodArgumentResolverComposite argumentResolvers); void setParameterNameDiscoverer(
			ParameterNameDiscoverer parameterNameDiscoverer); void setConversionService(ConversionService conversionService); void setObjectMapper(ObjectMapper objectMapper); @Nullable Object invoke(WampMessage message, List<Object> arguments,
			Map<String, Object> argumentsKw); @Nullable Object convert(MethodParameter parameter, Object argument);  }