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


Java MapType類代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.type.MapType的典型用法代碼示例。如果您正苦於以下問題:Java MapType類的具體用法?Java MapType怎麽用?Java MapType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MapType類屬於com.fasterxml.jackson.databind.type包,在下文中一共展示了MapType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateTenants

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的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.MapType; //導入依賴的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: fetchAll

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
@Override
public ListResult<T> fetchAll() {
    try {
        // get the data out..
        byte[] json = jsondb.getAsByteArray(getCollectionPath());
        if( json!=null && json.length > 0 ) {

            // Lets use jackson to parse the map of keys to our model instances
            ObjectMapper mapper = Json.mapper();
            TypeFactory typeFactory = mapper.getTypeFactory();
            MapType mapType = typeFactory.constructMapType(LinkedHashMap.class, String.class, getType());
            LinkedHashMap<String, T> map = mapper.readValue(json, mapType);

            return ListResult.of(map.values());
        }

        return ListResult.of(Collections.<T>emptyList());
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException|IOException e) {
        throw SyndesisServerException.launderThrowable(e);
    }
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:22,代碼來源:JsonDbDao.java

示例4: deserializeJsonStr

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的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

示例5: modifyMapDeserializer

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
@Override
public JsonDeserializer<?> modifyMapDeserializer(
		DeserializationConfig config, MapType type,
		BeanDescription beanDesc,
		JsonDeserializer<?> deserializer) {
	
	// statements
	if (isMapOfStringAndListOfStatements(type)) {
		return new ModifiedMapDeserializer<String, List<JacksonStatement>>(deserializer);
	}
	// labels and descriptions
	else if (isMapOfStringAndMonolingualTextValue(type)) {
		return new ModifiedMapDeserializer<String, JacksonMonolingualTextValue>(deserializer);
	}
	// sitelinks
	else if (isMapOfStringAndSitelink(type)) {
		return new ModifiedMapDeserializer<String, JacksonSiteLink>(deserializer);
	}
	// aliases and miscallaneous that does not need this workaround
	else {
		return deserializer;
	}
}
 
開發者ID:heindorf,項目名稱:cikm16-wdvd-feature-extraction,代碼行數:24,代碼來源:MapDeserializerModifier.java

示例6: fromBundle

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
public static JsonValueMap fromBundle(BundleName bundle, Locale locale) {
    JsonValueMap jvm = new JsonValueMap();
    jvm.setMapId(bundle.getValueMapId());

    URL resource = findResource(bundle.toString(), CONTROL, locale);
    if (resource == null) {
        return jvm;
    }
    ObjectMapper om = JsonUtils.defaultObjectMapper();
    try {
        TypeFactory typeFactory = om.getTypeFactory();
        MapType jsonType = typeFactory.constructMapType(Map.class, String.class, Object.class);
        Map<String, Object> jsonMap = om.readValue(resource, jsonType);
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine(String.valueOf(jsonMap));
        }
        Object data = jsonMap.get("data");
        jvm.setValues((List<Map<String, Object>>) data);
    } catch (Exception ex) {
        LOG.log(Level.WARNING, "Cannot read resource " + resource, ex);
    }
    return jvm;
}
 
開發者ID:proarc,項目名稱:proarc,代碼行數:24,代碼來源:JsonValueMap.java

示例7: jsonObjectMapper

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
@Bean
public ObjectMapper jsonObjectMapper() {
	final ObjectMapper jsonMapper = new ObjectMapper();
	jsonMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
	jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	jsonMapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
	jsonMapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
	jsonMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);

	final SimpleModule module = new SimpleModule("FieldsMapping", Version.unknownVersion());
	module.setSerializerModifier(new BeanSerializerModifier() {
		@Override
		public JsonSerializer<?> modifyMapSerializer(final SerializationConfig config, final MapType valueType,
				final BeanDescription beanDesc, final JsonSerializer<?> serializer) {
			if (FieldsMap.class.isAssignableFrom(valueType.getRawClass())) {
				return new FieldsMapMixInLikeSerializer();
			} else {
				return super.modifyMapSerializer(config, valueType, beanDesc, serializer);
			}
		}
	});
	jsonMapper.registerModule(module);
	return jsonMapper;
}
 
開發者ID:logsniffer,項目名稱:logsniffer,代碼行數:25,代碼來源:CoreAppConfig.java

示例8: typeFromId

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的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

示例9: readJsonFromClasspathAsMap

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
public static Map<String, Object> readJsonFromClasspathAsMap(String fileName) {
  InputStream inputStream = null;

  try {
    inputStream = IoUtil.getResourceAsStream(fileName);
    if (inputStream == null) {
      throw new RuntimeException("File '" + fileName + "' not found!");
    }

    MapType type = TypeFactory.defaultInstance().constructMapType(HashMap.class, String.class, Object.class);
    HashMap<String, Object> mapping = objectMapper.readValue(inputStream, type);

    return mapping;
  } catch (IOException e) {
    throw new RuntimeException("Unable to load json [" + fileName + "] from classpath", e);
  } finally {
    IoUtil.closeSilently(inputStream);
  }
}
 
開發者ID:camunda,項目名稱:camunda-bpm-elasticsearch,代碼行數:20,代碼來源:JsonHelper.java

示例10: bodyFromRequest

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
public static Map<String, Object> bodyFromRequest(RecordedRequest request) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    MapType mapType = mapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class);
    Buffer body = request.getBody();
    try {
        return mapper.readValue(body.inputStream(), mapType);
    } catch (IOException e) {
        throw e;
    } finally {
        body.close();
    }
}
 
開發者ID:auth0,項目名稱:Guardian.java,代碼行數:13,代碼來源:MockServer.java

示例11: receiveIndexingQueue

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
@JmsListener(destination = INDEXING_QUEUE)
public void receiveIndexingQueue(TurSNJob turSNJob) {
	logger.debug("Received job - " + INDEXING_QUEUE);
	JSONArray jsonRows = new JSONArray(turSNJob.getJson());
	TurSNSite turSNSite = this.turSNSiteRepository.findById(Integer.parseInt(turSNJob.getSiteId()));
	try {
		for (int i = 0; i < jsonRows.length(); i++) {
			JSONObject jsonRow = jsonRows.getJSONObject(i);
			logger.debug("receiveQueue JsonObject: " + jsonRow.toString());
			ObjectMapper mapper = new ObjectMapper();
			TypeFactory typeFactory = mapper.getTypeFactory();
			MapType mapType = typeFactory.constructMapType(HashMap.class, String.class, Object.class);
			HashMap<String, Object> attributes = mapper.readValue(new StringReader(jsonRow.toString()), mapType);

			Map<String, Object> consolidateResults = new HashMap<String, Object>();

			// SE
			for (Entry<String, Object> attribute : attributes.entrySet()) {
				logger.debug("SE Consolidate Value: " + attribute.getValue());
				logger.debug("SE Consolidate Class: " + attribute.getValue().getClass().getName());
				consolidateResults.put(attribute.getKey(), attribute.getValue());
			}

			// Remove Duplicate Terms
			Map<String, Object> attributesWithUniqueTerms = this.removeDuplicateTerms(consolidateResults);

			// SE
			turSolr.init(turSNSite, attributesWithUniqueTerms);
			turSolr.indexing();

		}
		
		logger.debug("Sent job - " + NLP_QUEUE);
		this.jmsMessagingTemplate.convertAndSend(NLP_QUEUE, turSNJob);
		
	} catch (Exception e) {
		e.printStackTrace();
	}
	
}
 
開發者ID:openviglet,項目名稱:turing,代碼行數:41,代碼來源:TurSNProcessQueue.java

示例12: getUnicodeEmojis

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
/**
 * A map of emojis to unicode
 *
 * @return A map of emoji names to unicode
 * @throws RuntimeException
 *             When the emoji file can't be found, read or parsed
 */
public static Map<String, String> getUnicodeEmojis(ObjectMapper objectMapper) {
    MapType mapType = TypeFactory.defaultInstance()
                                 .constructMapType(Map.class, String.class, String.class);
    try {
        return objectMapper.readValue(Resources.getResource(Constants.EMOJI_RESOURCE), mapType);
    } catch (IOException e) {
        throw new RuntimeException("Can't read emojis", e);
    }
}
 
開發者ID:OpenChatAlytics,項目名稱:OpenChatAlytics,代碼行數:17,代碼來源:LocalEmojiUtils.java

示例13: findMapDeserializer

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
@Override
public JsonDeserializer<?> findMapDeserializer(MapType type, DeserializationConfig config,
                                               BeanDescription beanDesc, KeyDeserializer keyDeserializer,
                                               TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer) {

    return forJavaType(type);
}
 
開發者ID:leangen,項目名稱:graphql-spqr,代碼行數:8,代碼來源:ConvertingDeserializers.java

示例14: modifyMapSerializer

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
@Override
public JsonSerializer<?> modifyMapSerializer(SerializationConfig config, MapType valueType,
    BeanDescription beanDesc, JsonSerializer<?> serializer) {
  if (serializer instanceof MapSerializer) {
    // TODO: We should probably be propagating the NON_EMPTY inclusion here, but it's breaking
    // discovery.
    return new DeepEmptyCheckingSerializer<>(serializer);
  }
  return serializer;
}
 
開發者ID:cloudendpoints,項目名稱:endpoints-java,代碼行數:11,代碼來源:ObjectMapperUtil.java

示例15: setupModule

import com.fasterxml.jackson.databind.type.MapType; //導入依賴的package包/類
@Override
public void setupModule(SetupContext context) {
    // Modify the Map serializer to the delegate if it matches Map<String, ?>
    context.addBeanSerializerModifier(new BeanSerializerModifier() {
        @Override
        public JsonSerializer<?> modifyMapSerializer(SerializationConfig config, MapType valueType, BeanDescription beanDesc,
                                                     JsonSerializer<?> serializer) {
            if (valueType.getKeyType().equals(SimpleType.construct(String.class))) {
                return new DelegatingMapSerializer(serializer);
            }
            return serializer;
        }
    });
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:15,代碼來源:LazyJsonModule.java


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