当前位置: 首页>>代码示例>>Java>>正文


Java TypeFactory.constructCollectionType方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.type.TypeFactory.constructCollectionType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeFactory.constructCollectionType方法的具体用法?Java TypeFactory.constructCollectionType怎么用?Java TypeFactory.constructCollectionType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.type.TypeFactory的用法示例。


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

示例1: deserializeJsonStr

import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的package包/类
/**
 * Helper method for deserializing a chat JSON response to a collection of objects.
 *
 * @param jsonStr
 *            The chat JSON response.
 * @param mapElement
 *            Chat JSON responses are actually maps with a single element. This argument is
 *            the value of the element to pull out from the map.
 * @param colClassElements
 *            The types of objects that the collection object will contain.
 * @param objMapper
 *            The JSON object mapper used to deserialize the JSON string.
 * @return A collection of elements of type <code>colClassElements</code>.
 */
private <T> Collection<T> deserializeJsonStr(String jsonStr, String mapElement,
                                             Class<T> colClassElements,
                                             ObjectMapper objMapper) {
    Map<String, Collection<T>> re;
    try {
        TypeFactory typeFactory = objMapper.getTypeFactory();
        CollectionType type = typeFactory.constructCollectionType(List.class, colClassElements);
        MapType thetype = typeFactory.constructMapType(HashMap.class,
                                                       typeFactory.constructType(String.class),
                                                       type);
        re = objMapper.readValue(jsonStr, thetype);
    } catch (IOException e) {
        LOG.error("Got exception when trying to deserialize list of {}", colClassElements, e);
        return Lists.newArrayListWithExpectedSize(0);
    }
    return re.get(mapElement);
}
 
开发者ID:OpenChatAlytics,项目名称:OpenChatAlytics,代码行数:32,代码来源:JsonHipChatDAO.java

示例2: getChangedContainers

import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的package包/类
private Map<String, ContainerQuota> getChangedContainers( final String quotaContainers ) throws java.io.IOException
{
    Map<String, ContainerQuota> changedContainersFiltered = new HashMap<>();
    TypeFactory typeFactory = mapper.getTypeFactory();
    CollectionType arrayType = typeFactory.constructCollectionType( ArrayList.class, ChangedContainerDto.class );
    List<ChangedContainerDto> changedContainers = mapper.readValue( quotaContainers, arrayType );
    for ( ChangedContainerDto cont : changedContainers )
    {
        ContainerQuotaDto containerQuotaDto = cont.getQuota();
        ContainerSize containerSize = containerQuotaDto.getContainerSize();
        ContainerQuota defaultQuota = ContainerSize.getDefaultContainerQuota( containerSize );
        if ( containerSize == ContainerSize.CUSTOM )
        {
            defaultQuota = containerQuotaDto.getContainerQuota();
        }

        changedContainersFiltered.put( cont.getHostId(), defaultQuota );
    }
    return changedContainersFiltered;
}
 
开发者ID:subutai-io,项目名称:base,代码行数:21,代码来源:RestServiceImpl.java

示例3: deserializeJsonStr

import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的package包/类
/**
 * Helper method for deserializing lists of elements of type <code>T</code> from a response JSON
 * string
 *
 * @param jsonStr
 *            The API returned JSON string
 * @param listElements
 *            A list of ordered elements in the original response JSON to traverse down to to
 *            get to the element that contains the list of items of type <code>T</code> to
 *            deserialize
 *            <p/>
 *            For example given the following JSON string
 *
 * <pre>
 *            {
 *                "someElement": {
 *                    "someInnerElement": [
 *                        {...},
 *                        {...}
 *                    ],
 *                    "otherElement": "value"
 *                }
 *            }
 * </pre>
 *
 *            If the collection of <code>T</code>s we were interested in were inside
 *            <code>someInnerEllement</code> then the list would equal:
 *            <code>[someElement, someInnterElement]</code>
 * @param clazz
 *            The class to deserialize The JSON object mapper used to deserialize the JSON
 *            string.
 * @return A collection of elements of type <code>clazz</code>.
 */
private <T> Collection<T> deserializeJsonStr(String jsonStr, List<String> listElements,
                                             Class<T> clazz,
                                             ObjectMapper objMapper) {
    TypeFactory typeFactory = objMapper.getTypeFactory();
    CollectionType type = typeFactory.constructCollectionType(List.class, clazz);
    try {
        JsonNode jsonNode = objMapper.readTree(jsonStr);
        // traverse down the order of elements until the desired one is reached
        for (String jsonEl : listElements) {
            jsonNode = jsonNode.get(jsonEl);
            if (jsonNode == null) {
                return ImmutableList.of();
            }
        }
        return objMapper.readValue(jsonNode.toString(), type);
    } catch (IOException e) {
        LOG.error("Got exception when trying to deserialize list of {}", clazz, e);
        return ImmutableList.of();
    }
}
 
开发者ID:OpenChatAlytics,项目名称:OpenChatAlytics,代码行数:54,代码来源:JsonSlackDAO.java

示例4: parseNodes

import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的package包/类
private List<NodeSchemaDto> parseNodes( final String nodes ) throws java.io.IOException
{
    TypeFactory typeFactory = mapper.getTypeFactory();
    CollectionType arrayType = typeFactory.constructCollectionType( ArrayList.class, NodeSchemaDto.class );
    return mapper.readValue( nodes, arrayType );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:7,代码来源:RestServiceImpl.java

示例5: serialize

import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的package包/类
@Override
public void serialize(List<Link> value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonGenerationException {

    // sort links according to their relation
    Map<String, List<Object>> sortedLinks = new LinkedHashMap<String, List<Object>>();
    List<Link> links = new ArrayList<Link>();

    boolean prefixingRequired = curieProvider != null;
    boolean curiedLinkPresent = false;
    boolean skipCuries = !jgen.getOutputContext().getParent().inRoot();

    Object currentValue = jgen.getCurrentValue();

    if (currentValue instanceof Resources) {
        if (mapper.hasCuriedEmbed((Resources<?>) currentValue)) {
            curiedLinkPresent = true;
        }
    }

    for (Link link : value) {

        if (link.equals(CURIES_REQUIRED_DUE_TO_EMBEDS)) {
            continue;
        }

        String rel = prefixingRequired ? curieProvider.getNamespacedRelFrom(link) : link.getRel();

        if (!link.getRel().equals(rel)) {
            curiedLinkPresent = true;
        }

        if (sortedLinks.get(rel) == null) {
            sortedLinks.put(rel, new ArrayList<Object>());
        }

        links.add(link);

        sortedLinks.get(rel).add(toHalLink(link));
    }

    if (!skipCuries && prefixingRequired && curiedLinkPresent) {

        ArrayList<Object> curies = new ArrayList<Object>();
        curies.add(curieProvider.getCurieInformation(new Links(links)));

        sortedLinks.put("curies", curies);
    }

    TypeFactory typeFactory = provider.getConfig().getTypeFactory();
    JavaType keyType = typeFactory.uncheckedSimpleType(String.class);
    JavaType valueType = typeFactory.constructCollectionType(ArrayList.class, Object.class);
    JavaType mapType = typeFactory.constructMapType(HashMap.class, keyType, valueType);

    MapSerializer serializer = MapSerializer.construct(new String[]{}, mapType, true, null,
            provider.findKeySerializer(keyType, null), new OptionalListJackson2Serializer(property), null);

    serializer.serialize(sortedLinks, jgen, provider);
}
 
开发者ID:mockitoo,项目名称:spring-data-rest-android,代码行数:60,代码来源:Jackson2HalModule.java

示例6: 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

示例7: decodeToList

import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的package包/类
/***
 *  将传入的json,转换为T类型的List集合
 *  @param json json
 *  @param t t
 *  @param <T> T
 *  @return result
 *  @throws IOException error
 */
public static <T> List<T> decodeToList(String json, Class<T> t) throws IOException {
    final TypeFactory factory = mapper.getTypeFactory();
    final JavaType listOfT = factory.constructCollectionType(List.class, t);
    return mapper.readValue(json, listOfT);
}
 
开发者ID:numsg,项目名称:spring-boot-seed,代码行数:14,代码来源:JsonUtil.java


注:本文中的com.fasterxml.jackson.databind.type.TypeFactory.constructCollectionType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。