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


Java CollectionType类代码示例

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


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

示例1: updateTenants

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
@SneakyThrows
private void updateTenants(String key, String config) {
    log.info("Tenants list was updated");

    if (!TENANTS_LIST_CONFIG_KEY.equals(key)) {
        throw new IllegalArgumentException("Wrong config key to update " + key);
    }

    assertExistsTenantsListConfig(config);

    CollectionType setType = defaultInstance().constructCollectionType(HashSet.class, TenantState.class);
    MapType type = defaultInstance().constructMapType(HashMap.class, defaultInstance().constructType(String.class), setType);
    Map<String, Set<TenantState>> tenantsByServiceMap = objectMapper.readValue(config, type);
    Set<TenantState> tenantKeys = tenantsByServiceMap.get(applicationName);

    assertExistTenants(tenantKeys);

    this.tenants = tenantKeys;
    this.suspendedTenants = tenantKeys.stream().filter(tenant -> SUSPENDED_STATE.equals(tenant.getState()))
        .map(TenantState::getName).collect(Collectors.toSet());
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:22,代码来源:TenantListRepository.java

示例2: updateTenants

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
@SneakyThrows
private void updateTenants(String config)  {
    log.info("Tenants list was updated");

    CollectionType setType = defaultInstance().constructCollectionType(HashSet.class, TenantState.class);
    MapType type = defaultInstance().constructMapType(HashMap.class, defaultInstance().constructType(String.class), setType);
    Map<String, Set<TenantState>> tenantsByServiceMap = objectMapper.readValue(config, type);

    final Map<String, String> tenants = new HashMap<>();
    for (TenantState tenant: tenantsByServiceMap.getOrDefault(applicationName, emptySet())) {
        for (String host : hosts) {
            tenants.put(tenant.getName() + "." + host, tenant.getName().toUpperCase());
        }
    }

    this.tenants = tenants;
}
 
开发者ID:xm-online,项目名称:xm-gate,代码行数:18,代码来源:TenantMappingServiceImpl.java

示例3: deserializeWithRetry

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
private Collection<Object> deserializeWithRetry(JsonParser p, DeserializationContext ctxt, JavaType contentType) throws IOException {
    final CollectionType collectionType = ctxt.getTypeFactory().constructCollectionType(Collection.class, contentType);

    try {
        return p.getCodec().readValue(p, collectionType);

    } catch (JsonMappingException e) {
        // attempt to read the value as string
        final String escapedString = p.getValueAsString();

        // stop here if value could not be read
        if (isNull(escapedString)) {
            throw ctxt.instantiationException(Collection.class, "Read null value when attempting to deserialize " + collectionType.toString());
        }

        // un-escape double quotes
        String unescapedString = escapedString.replaceAll("\"", "\"");

        // and attempt to parse again
        return new ObjectMapper().readValue(unescapedString, collectionType);
    }
}
 
开发者ID:salesforce,项目名称:pyplyn,代码行数:23,代码来源:RawJsonCollectionDeserializer.java

示例4: fromJson

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
/**
 * 反序列化复杂Collection如List<Bean>
 *
 * @param <L>             the type parameter
 * @param <E>             the type parameter
 * @param jsonString      the json string
 * @param collectionClass the collection class
 * @param elementClass    the element class
 * @return 转换失败时返回 null
 */
public static <L extends Collection<E>, E> L fromJson(String jsonString,
                                                      Class<L> collectionClass,
                                                      Class<E> elementClass) {
    if (!StringUtils.hasText(jsonString)) {
        return null;
    }
    try {
        CollectionType type = mapper.getTypeFactory().constructCollectionType(collectionClass,
                elementClass);
        return mapper.readValue(jsonString, type);
    } catch (Exception e) {
        (new JsonUtil()).logger.error(e.getMessage(), e);
        return null;
    }
}
 
开发者ID:numsg,项目名称:spring-boot-seed,代码行数:26,代码来源:JsonUtil.java

示例5: deserializeJsonStr

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的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

示例6: setupModule

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
@Override
public void setupModule(final SetupContext context) {
    super.setupModule(context);
    context.addBeanDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyCollectionDeserializer(final DeserializationConfig config,
                                                                final CollectionType type,
                                                                final BeanDescription beanDesc,
                                                                final JsonDeserializer<?> deserializer) {
            if (deserializer instanceof CollectionDeserializer) {
                return new ListDeserializer((CollectionDeserializer) deserializer);
            } else {
                return super.modifyCollectionDeserializer(config, type, beanDesc,
                        deserializer);
            }
        }
    });
}
 
开发者ID:allure-framework,项目名称:allure2,代码行数:19,代码来源:XmlParserModule.java

示例7: testCustomDeserializerForCustomLists

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
@Test
public void testCustomDeserializerForCustomLists() throws Exception {
    final CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    when(response.getStatusLine()).thenReturn(HTTP_200_STATUS_LINE);
    when(response.getEntity()).thenReturn(new StringEntity("{results: [{field : \"SomeValue\"}], results_count: 1}"));
    final CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
    when(httpClient.execute(any(HttpHost.class), any(HttpRequest.class), any(HttpClientContext.class))).thenReturn(response);
    final RestClient restClient = new BasicRestClient(httpClient, HttpClientContext.create(), "localhost");
    final Class<? extends CollectionType> clazzListOfTestPojo = new ObjectMapper().getTypeFactory().constructCollectionType(List.class, TestPojo.class).getClass();
    final RESTServiceConnector connector = new RESTServiceConnector.Builder()
            .client(restClient)
            .classToDeserializerEntry(clazzListOfTestPojo, new CustomListDeserializer<TestPojoDeserializer>())
            .build();

    connector.executeRetrieveObject(TestPojo.class, "/somepath");
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:RESTServiceConnectorTest.java

示例8: getChangedContainers

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的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

示例9: unmarshal

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {

        // is there a header with the unmarshal type?
        Class<?> clazz = unmarshalType;
        String type = exchange.getIn().getHeader(JacksonConstants.UNMARSHAL_TYPE, String.class);
        if (type == null && isAllowJmsType()) {
            type = exchange.getIn().getHeader("JMSType", String.class);
        }
        if (type != null) {
            clazz = exchange.getContext().getClassResolver().resolveMandatoryClass(type);
        }
        if (collectionType != null) {
            CollectionType collType = objectMapper.getTypeFactory().constructCollectionType(collectionType, clazz);
            return this.objectMapper.readValue(stream, collType);
        } else {
            return this.objectMapper.readValue(stream, clazz);
        }
    }
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:JacksonDataFormat.java

示例10: unmarshal

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {

        // is there a header with the unmarshal type?
        Class<?> clazz = unmarshalType;
        String type = exchange.getIn().getHeader(JacksonXMLConstants.UNMARSHAL_TYPE, String.class);
        if (type == null && isAllowJmsType()) {
            type = exchange.getIn().getHeader("JMSType", String.class);
        }
        if (type != null) {
            clazz = exchange.getContext().getClassResolver().resolveMandatoryClass(type);
        }
        if (collectionType != null) {
            CollectionType collType = xmlMapper.getTypeFactory().constructCollectionType(collectionType, clazz);
            return this.xmlMapper.readValue(stream, collType);
        } else {
            return this.xmlMapper.readValue(stream, clazz);
        }
    }
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:JacksonXMLDataFormat.java

示例11: convertAndSaveFeatures

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
@Override
public void convertAndSaveFeatures(
    final String testRunId,
    final InputStream featureStream,
    final Optional<String> group,
    final boolean dryRun,
    final boolean onlyNewScenarii,
    final boolean mergeOnlyNewPassedScenarii) {
    final CollectionType featureListJavaType = objectMapper.getTypeFactory().constructCollectionType(List.class, ReportFeature.class);
    try {
        final List<ReportFeature> reportFeatures = objectMapper.readValue(featureStream, featureListJavaType);
        for (final ReportFeature reportFeature : reportFeatures) {
            convertAndSaveFeature(testRunId, reportFeature, group, dryRun, onlyNewScenarii, mergeOnlyNewPassedScenarii);
        }
    } catch (final IOException e) {
        throw new IllegalStateException("Can't parse report feature stream", e);
    }
}
 
开发者ID:pgentile,项目名称:zucchini-ui,代码行数:19,代码来源:ReportConverterServiceImpl.java

示例12: getLatestTime

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
/**
 * @param host
 * @param port
 * @param collection
 * @return
 *  The latest segment available at the ThirdEye server.
 * @throws IOException
 */
public static long getLatestTime(String host, short port, String collection) throws IOException {
  String urlString = "http://" + host + ":" + port + "/collections/" + collection + "/segments";
  URL url = new URL(urlString);
  final CollectionType listType = OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class,
      SegmentDescriptor.class);
  List<SegmentDescriptor> segments = OBJECT_MAPPER.readValue(new InputStreamReader(url.openStream(), "UTF-8"),
      listType);
  DateTime latestDataTime = null;
  for (SegmentDescriptor segment : segments) {
    if (segment.getEndDataTime() != null && (latestDataTime == null ||
        segment.getEndDataTime().compareTo(latestDataTime) > 0)) {
      latestDataTime = segment.getEndDataTime();
    }
  }
  return latestDataTime.getMillis();
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:25,代码来源:ThirdEyeServerUtils.java

示例13: typeFromId

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
@Override
public JavaType typeFromId(DatabindContext context, String id) {
  DeserializationContext ctx = (DeserializationContext) context;
  Map<String, Class> map = (Map) ctx.getAttribute("secucardobjectmap");

  Class type = map.get(id);

  JavaType javatype;
  if (type == null) {
    javatype = MapType.construct(HashMap.class, SimpleType.construct(String.class), SimpleType.construct(Object.class));
  } else {
    javatype = SimpleType.construct(type);
  }

  if (JsonToken.END_ARRAY.equals(ctx.getParser().getCurrentToken())) {
    // it is expected to get called here when reading the last token.
    javatype = CollectionType.construct(ArrayList.class, javatype);
  }

  return javatype;
}
 
开发者ID:secucard,项目名称:secucard-connect-java-sdk,代码行数:22,代码来源:ObjectIdTypeResolver.java

示例14: findCollectionDeserializer

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
@Override
public JsonDeserializer<?> findCollectionDeserializer(CollectionType type, DeserializationConfig config, BeanDescription beanDesc,
        TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer) throws JsonMappingException
{
    Class<?> raw = type.getRawClass();
    if (CollectionF.class.isAssignableFrom(raw)) {
        if (Option.class.isAssignableFrom(raw)) {
            return new OptionDeserializer(type, elementTypeDeserializer, elementDeserializer);
        }
        if (ListF.class.isAssignableFrom(raw)) {
            return new ListFDeserializer(type, elementTypeDeserializer, elementDeserializer);
        }
        if (SetF.class.isAssignableFrom(raw)) {
            return new SetFDeserializer(type, elementTypeDeserializer, elementDeserializer);
        }
        return new ListFDeserializer(type, elementTypeDeserializer, elementDeserializer);
    }
    return null;
}
 
开发者ID:v1ctor,项目名称:jackson-datatype-bolts,代码行数:20,代码来源:BoltsDeserializers.java

示例15: tableNames

import com.fasterxml.jackson.databind.type.CollectionType; //导入依赖的package包/类
/** Reads data source names from Druid. */
Set<String> tableNames() {
  final Map<String, String> requestHeaders =
      ImmutableMap.of("Content-Type", "application/json");
  final String data = null;
  final String url = coordinatorUrl + "/druid/coordinator/v1/metadata/datasources";
  if (CalcitePrepareImpl.DEBUG) {
    System.out.println("Druid: table names" + data + "; " + url);
  }
  try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000);
       InputStream in = traceResponse(in0)) {
    final ObjectMapper mapper = new ObjectMapper();
    final CollectionType listType =
        mapper.getTypeFactory().constructCollectionType(List.class,
            String.class);
    final List<String> list = mapper.readValue(in, listType);
    return ImmutableSet.copyOf(list);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:DruidConnectionImpl.java


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