本文整理汇总了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;
}
示例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);
}
示例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())));
}
示例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())));
}
示例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);
}
}