• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TypeUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.util.TypeUtils的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils类的具体用法?Java TypeUtils怎么用?Java TypeUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TypeUtils类属于org.springframework.util包,在下文中一共展示了TypeUtils类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: isSwaggerWrapBody

import org.springframework.util.TypeUtils; //导入依赖的package包/类
protected boolean isSwaggerWrapBody(ArgumentsMapperConfig config, List<ProviderParameter> providerNormalParams) {
  Method swaggerMethod = config.getSwaggerMethod();
  if (swaggerMethod.getParameterCount() != 1) {
    return false;
  }

  Type swaggerType = config.getSwaggerMethod().getGenericParameterTypes()[0];
  if (!swaggerType.getClass().equals(Class.class)) {
    return false;
  }

  Type firstProviderParam = providerNormalParams.get(0).getType();
  if (TypeUtils.isAssignable(firstProviderParam, swaggerType)) {
    return false;
  }

  swaggerType = ((Class<?>) swaggerType).getFields()[0].getGenericType();
  Converter converter = converterMgr.findConverter(type, firstProviderParam, swaggerType);
  if (ConverterCommon.class.isInstance(converter)) {
    return false;
  }
  // 透明rpc的包装场景
  return true;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:ArgumentsMapperFactory.java


示例2: findMethod

import org.springframework.util.TypeUtils; //导入依赖的package包/类
/**
 * Returns the requested method from an object instance.
 * 
 * @param methodName Name of the setter method.
 * @param instance Object instance to search.
 * @param valueClass The desired property return type (null if don't care).
 * @param setter If true, search for setter method signature. If false, getter method signature.
 * @return The requested method.
 * @throws NoSuchMethodException If method was not found.
 */
private static Method findMethod(String methodName, Object instance, Class<?> valueClass, boolean setter)
                                                                                                         throws NoSuchMethodException {
    if (methodName == null) {
        return null;
    }
    
    int paramCount = setter ? 1 : 0;
    
    for (Method method : instance.getClass().getMethods()) {
        if (method.getName().equals(methodName) && method.getParameterTypes().length == paramCount) {
            Class<?> targetClass = setter ? method.getParameterTypes()[0] : method.getReturnType();
            
            if (valueClass == null || TypeUtils.isAssignable(targetClass, valueClass)) {
                return method;
            }
        }
    }
    
    throw new NoSuchMethodException("Compatible method not found: " + methodName);
    
}
 
开发者ID:carewebframework,项目名称:carewebframework-core,代码行数:32,代码来源:PropertyUtil.java


示例3: writeInternal

import org.springframework.util.TypeUtils; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {

	JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
	JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
	try {

		JavaType javaType = null;
		if (jackson26Available && type != null && object != null && TypeUtils.isAssignable(type, object.getClass())) {
			javaType = getJavaType(type, null);
		}
		ObjectWriter objectWriter;
		objectWriter = this.objectMapper.writer();
		if (javaType != null && javaType.isContainerType()) {
			objectWriter = objectWriter.withType(javaType);
		}
		objectWriter.writeValue(generator, object);

		generator.flush();

	}
	catch (JsonProcessingException ex) {
		throw new HttpMessageNotWritableException("Could not write content: " + ex.getMessage(), ex);
	}
}
 
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:28,代码来源:AbstractJackson2HttpMessageConverter.java


示例4: shouldInvokeOnReturnValueOf

import org.springframework.util.TypeUtils; //导入依赖的package包/类
/**
 * Following AspectJ semantics, if a returning clause was specified, then the
 * advice is only invoked if the returned value is an instance of the given
 * returning type and generic type parameters, if any, match the assignment
 * rules. If the returning type is Object, the advice is *always* invoked.
 * @param returnValue the return value of the target method
 * @return whether to invoke the advice method for the given return value
 */
private boolean shouldInvokeOnReturnValueOf(Method method, Object returnValue) {
	Class<?> type = getDiscoveredReturningType();
	Type genericType = getDiscoveredReturningGenericType();
	// If we aren't dealing with a raw type, check if generic parameters are assignable.
	return (matchesReturnValue(type, method, returnValue) &&
			(genericType == null || genericType == type ||
					TypeUtils.isAssignable(genericType, method.getGenericReturnType())));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:AspectJAfterReturningAdvice.java


示例5: supports

import org.springframework.util.TypeUtils; //导入依赖的package包/类
@Override
public boolean supports(MethodParameter returnType,
		Class<? extends HttpMessageConverter<?>> converterType) {
	returnType.increaseNestingLevel();
	Type nestedType = returnType.getNestedGenericParameterType();
	returnType.decreaseNestingLevel();
	return ResourceSupport.class.isAssignableFrom(returnType.getParameterType())
			|| TypeUtils.isAssignable(ResourceSupport.class, nestedType);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:EndpointWebMvcHypermediaManagementContextConfiguration.java


示例6: shouldInvokeOnReturnValueOf

import org.springframework.util.TypeUtils; //导入依赖的package包/类
/**
 * Following AspectJ semantics, if a returning clause was specified, then the
 * advice is only invoked if the returned value is an instance of the given
 * returning type and generic type parameters, if any, match the assignment
 * rules. If the returning type is Object, the advice is *always* invoked.
 * @param returnValue the return value of the target method
 * @return whether to invoke the advice method for the given return value
 */
private boolean shouldInvokeOnReturnValueOf(Method method, Object returnValue) {
	Class type = getDiscoveredReturningType();
	Type genericType = getDiscoveredReturningGenericType();
	// If we aren't dealing with a raw type, check if  generic parameters are assignable.
	return (ClassUtils.isAssignableValue(type, returnValue) &&
			(genericType == null || genericType == type ||
					TypeUtils.isAssignable(genericType, method.getGenericReturnType())));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:AspectJAfterReturningAdvice.java


示例7: writeInternal

import org.springframework.util.TypeUtils; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {

	JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
	JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
	try {
		writePrefix(generator, object);

		Class<?> serializationView = null;
		FilterProvider filters = null;
		Object value = object;
		JavaType javaType = null;
		if (object instanceof MappingJacksonValue) {
			MappingJacksonValue container = (MappingJacksonValue) object;
			value = container.getValue();
			serializationView = container.getSerializationView();
			filters = container.getFilters();
		}
		if (jackson26Available && type != null && value != null && TypeUtils.isAssignable(type, value.getClass())) {
			javaType = getJavaType(type, null);
		}
		ObjectWriter objectWriter;
		if (serializationView != null) {
			objectWriter = this.objectMapper.writerWithView(serializationView);
		}
		else if (filters != null) {
			objectWriter = this.objectMapper.writer(filters);
		}
		else {
			objectWriter = this.objectMapper.writer();
		}
		if (javaType != null && javaType.isContainerType()) {
			objectWriter = objectWriter.withType(javaType);
		}
		objectWriter.writeValue(generator, value);

		writeSuffix(generator, object);
		generator.flush();

	}
	catch (JsonProcessingException ex) {
		throw new HttpMessageNotWritableException("Could not write content: " + ex.getMessage(), ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:47,代码来源:AbstractJackson2HttpMessageConverter.java



注:本文中的org.springframework.util.TypeUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PropertySetter类代码示例发布时间:2022-05-22
下一篇:
Java GetSnapshottableDirListingRequestProto类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap