當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。