本文整理汇总了Java中com.fasterxml.jackson.databind.type.TypeFactory.constructParametricType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeFactory.constructParametricType方法的具体用法?Java TypeFactory.constructParametricType怎么用?Java TypeFactory.constructParametricType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.type.TypeFactory
的用法示例。
在下文中一共展示了TypeFactory.constructParametricType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateValueType
import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的package包/类
/**
* Generates a {@link JavaType} that matches the target Thrift field represented by the provided
* {@code <E>} enumerated value. If the field's type includes generics, the generics will
* be added to the generated {@link JavaType} to support proper conversion.
* @param thriftInstance The Thrift-generated class instance that will be converted to/from JSON.
* @param field A {@code <E>} enumerated value that represents a field in a Thrift-based entity.
* @return The {@link JavaType} representation of the type associated with the field.
* @throws NoSuchFieldException if unable to determine the field's type.
* @throws SecurityException if unable to determine the field's type.
*/
protected JavaType generateValueType(final T thriftInstance, final E field) throws NoSuchFieldException, SecurityException {
final TypeFactory typeFactory = TypeFactory.defaultInstance();
final Field declaredField = thriftInstance.getClass().getDeclaredField(field.getFieldName());
if(declaredField.getType().equals(declaredField.getGenericType())) {
log.debug("Generating JavaType for type '{}'.", declaredField.getType());
return typeFactory.constructType(declaredField.getType());
} else {
final ParameterizedType type = (ParameterizedType)declaredField.getGenericType();
final Class<?>[] parameterizedTypes = new Class<?>[type.getActualTypeArguments().length];
for(int i=0; i<type.getActualTypeArguments().length; i++) {
parameterizedTypes[i] = (Class<?>)type.getActualTypeArguments()[i];
}
log.debug("Generating JavaType for type '{}' with generics '{}'", declaredField.getType(), parameterizedTypes);
return typeFactory.constructParametricType(declaredField.getType(), parameterizedTypes);
}
}
示例2: redisCacheManager
import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的package包/类
@Bean
public CacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
RedisCacheManager cacheManager = new RedisCacheManager(redisConnectionFactory);
TypeFactory typeFactory = TypeFactory.defaultInstance();
// Post Cache
JsonRedisTemplate<? extends Object> postTemplate = new JsonRedisTemplate<>(redisConnectionFactory, PostService.CACHE_TYPE);
cacheManager.withCache(PostService.CACHE_NAME, postTemplate, cacheTimeToLive);
// Post List Cache
JavaType posts = typeFactory.constructParametricType(ArrayList.class, PostService.CACHE_TYPE);
JsonRedisTemplate<? extends Object> postsTemplate = new JsonRedisTemplate<>(redisConnectionFactory, posts);
cacheManager.withCache(PostService.CACHES_NAME, postsTemplate, cacheTimeToLive);
JsonRedisTemplate<? extends Object> realtimePosts = new JsonRedisTemplate<>(redisConnectionFactory, posts);
cacheManager.withCache(PostService.CACHES_REALTIME_NAME, realtimePosts, cacheTimeToLiveShort);
// Tag Cache
JsonRedisTemplate<? extends Object> tagTemplate = new JsonRedisTemplate<>(redisConnectionFactory, TagService.CACHE_TYPE);
cacheManager.withCache(TagService.CACHE_NAME, tagTemplate, cacheTimeToLive);
// Tag List Cache
JavaType tags = typeFactory.constructParametricType(ArrayList.class, TagService.CACHE_TYPE);
JsonRedisTemplate<? extends Object> tagsTemplate = new JsonRedisTemplate<>(redisConnectionFactory, tags);
cacheManager.withCache(TagService.CACHES_NAME, tagsTemplate, cacheTimeToLive);
// Category Cache
JsonRedisTemplate<? extends Object> cateTemplate = new JsonRedisTemplate<>(redisConnectionFactory, CategoryService.CACHE_TYPE);
cacheManager.withCache(CategoryService.CACHE_NAME, cateTemplate, cacheTimeToLive);
// Category List Cache
JavaType cates = typeFactory.constructParametricType(ArrayList.class, CategoryService.CACHE_TYPE);
JsonRedisTemplate<? extends Object> catesTemplate = new JsonRedisTemplate<>(redisConnectionFactory, cates);
cacheManager.withCache(CategoryService.CACHES_NAME, catesTemplate, cacheTimeToLive);
// Reply Cache
JsonRedisTemplate<? extends Object> replyTemplate = new JsonRedisTemplate<>(redisConnectionFactory, ReplyService.CACHE_TYPE);
cacheManager.withCache(ReplyService.CACHE_NAME, replyTemplate, cacheTimeToLive);
// Reply List Cache
JavaType replies = typeFactory.constructParametricType(ArrayList.class, ReplyService.CACHE_TYPE);
JsonRedisTemplate<? extends Object> repliesTemplate = new JsonRedisTemplate<>(redisConnectionFactory, replies);
cacheManager.withCache(ReplyService.CACHES_NAME, repliesTemplate, cacheTimeToLive);
// Permission
JavaType permissions = typeFactory.constructCollectionType(ArrayList.class, PermissionService.CACHE_TYPE);
JsonRedisTemplate<Object> permissionsTemplate = new JsonRedisTemplate<>(redisConnectionFactory, permissions);
cacheManager.withCache(PermissionService.CACHES_NAME, permissionsTemplate, cacheTimeToLive);
JsonRedisTemplate<? extends Object> permissionTemplate = new JsonRedisTemplate<>(redisConnectionFactory, PermissionService.CACHE_TYPE);
cacheManager.withCache(PermissionService.CACHE_NAME, permissionTemplate, cacheTimeToLive);
// Role
JsonRedisTemplate<? extends Object> roleTemplte = new JsonRedisTemplate<>(redisConnectionFactory, RoleService.CACHE_TYPE);
cacheManager.withCache(RoleService.CACHE_NAME, roleTemplte, cacheTimeToLive);
//Oauth
JsonRedisTemplate<String> oauthTemplte = new JsonRedisTemplate<>(redisConnectionFactory, String.class);
cacheManager.withCache(OAuth2Service.CACHE_CODE, oauthTemplte, OAuth2Service.cacheTimeToLiveCode);
JsonRedisTemplate<String> tokenTemplte = new JsonRedisTemplate<>(redisConnectionFactory, String.class);
cacheManager.withCache(OAuth2Service.CACHE_ACCESSTOKEN, tokenTemplte, OAuth2Service.cacheTimeToLiveToken);
return cacheManager;
}