You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/09/08 07:14:17 UTC

[GitHub] [servicecomb-java-chassis] five111 commented on issue #2556: path的参数解析

five111 commented on issue #2556:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2556#issuecomment-914982267


   spring在处理path参数的时候
   通过HandlerMethodArgumentResolverComposite装载PathVariableMethodArgumentResolver这个类
   对传参类型和目标参数类型进行判断 最后通过StringToArrayConverter 中的convert方法 实现将参数由含“,”的字符串改造成目标的数组
   `
   	@Override
   	@Nullable
   	public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
   		if (source == null) {
   			return null;
   		}
   		String string = (String) source;
                   // 这一步做的转化
   		String[] fields = StringUtils.commaDelimitedListToStringArray(string);
   		TypeDescriptor targetElementType = targetType.getElementTypeDescriptor();
   		Assert.state(targetElementType != null, "No target element type");
   		Object target = Array.newInstance(targetElementType.getType(), fields.length);
   		for (int i = 0; i < fields.length; i++) {
   			String sourceElement = fields[i];
   			Object targetElement = this.conversionService.convert(sourceElement.trim(), sourceType, targetElementType);
   			Array.set(target, i, targetElement);
   		}
   		return target;
   	}
   
   }
   `
   servicecomb中有没有类似的机制去处理这些参数?
   我在 swagger-invocation-core中看到了类似的的 Converter的类,例如FileToPartConverter, 是否有可以拓展的机制?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org