本文整理汇总了Java中com.fasterxml.jackson.databind.type.TypeFactory.constructMapType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeFactory.constructMapType方法的具体用法?Java TypeFactory.constructMapType怎么用?Java TypeFactory.constructMapType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.type.TypeFactory
的用法示例。
在下文中一共展示了TypeFactory.constructMapType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchAll
import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的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);
}
}
示例2: 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);
}
示例3: receiveIndexingQueue
import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的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();
}
}
示例4: constructMapType
import com.fasterxml.jackson.databind.type.TypeFactory; //导入方法依赖的package包/类
private MapType constructMapType(Ctx pc, TypeFactory typeFactory) {
return typeFactory.constructMapType(LinkedHashMap.class, typeFactory.constructType(String.class), pc.getType().getContentType());
}
示例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);
}