當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeFactory.constructParametricType方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:SciGaP,項目名稱:allocateme,代碼行數:28,代碼來源:AbstractThriftDeserializer.java

示例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;
}
 
開發者ID:microacup,項目名稱:microbbs,代碼行數:66,代碼來源:CacheConfig.java


注:本文中的com.fasterxml.jackson.databind.type.TypeFactory.constructParametricType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。