本文整理汇总了Java中org.springframework.data.util.TypeInformation.isMap方法的典型用法代码示例。如果您正苦于以下问题:Java TypeInformation.isMap方法的具体用法?Java TypeInformation.isMap怎么用?Java TypeInformation.isMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.util.TypeInformation
的用法示例。
在下文中一共展示了TypeInformation.isMap方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapColumns
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* @param properties properties of array/collection types, must not be {@literal null}.
* @return list of columns of crate type array
* @throws {@link InvalidCrateApiUsageException}
*/
public List<Column> mapColumns(Set<CratePersistentProperty> properties) {
List<Column> columns = new LinkedList<>();
for(CratePersistentProperty property : properties) {
TypeInformation<?> typeInformation = from(property.getComponentType());
// safety check
if(property.isCollectionLike() && typeInformation.isMap()) {
// could be a list or an array
TypeInformation<?> actualType = property.getTypeInformation().getActualType();
// get the map's key type
Class<?> componentType = actualType.getTypeArguments().get(0).getType();
checkMapKey(componentType);
columns.add(createColumn(property));
}
}
return columns;
}
示例2: toCrateDocument
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
*
* @param root container for the converted payload
* @param payload value to be converted to {@link CrateDocument}
*/
@SuppressWarnings("unchecked")
private void toCrateDocument(CrateDocument root, Object payload) {
Map<String, Object> map = (Map<String, Object>)payload;
for(Entry<String, Object> entry : map.entrySet()) {
TypeInformation<?> type = getTypeInformation(entry.getValue().getClass());
if(type.isMap()) {
CrateDocument document = new CrateDocument();
toCrateDocument(document, entry.getValue());
logger.debug("converted '{}' to CrateDocument", entry.getKey());
root.put(entry.getKey(), document);
}else if(type.isCollectionLike()) {
CrateArray array = new CrateArray();
toCrateArray(array, entry.getValue());
logger.debug("converted '{}' to CrateArray", entry.getKey());
root.put(entry.getKey(), array);
}else {
// simple type
root.put(entry.getKey(), entry.getValue());
}
}
}
示例3: toCrateArray
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Nesting Array or Collection types is not supported by crate. It is safe to assume that the payload
* will contain either a Map or a primitive type. Map types will be converted to {@link CrateDocument}
* while simple types will be added without any conversion
* @param array {@link CrateArray} for adding either Map or Simple types
* @param payload containing either a Map or primitive type.
*/
@SuppressWarnings("unchecked")
private void toCrateArray(CrateArray array, Object payload) {
Collection<Object> objects = (Collection<Object>)(payload.getClass().isArray() ? asList((Object[])payload) : payload);
for(Object object : objects) {
TypeInformation<?> type = getTypeInformation(object.getClass());
if(type.isMap()) {
CrateDocument document = new CrateDocument();
toCrateDocument(document, object);
array.add(document);
}else {
array.add(object);
}
}
}
示例4: read
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <S> S read(TypeInformation<S> type, Object source) {
SecretDocument secretDocument = getSecretDocument(source);
TypeInformation<? extends S> typeToUse = secretDocument != null ? typeMapper
.readType(secretDocument.getBody(), type)
: (TypeInformation) ClassTypeInformation.OBJECT;
Class<? extends S> rawType = typeToUse.getType();
if (conversions.hasCustomReadTarget(source.getClass(), rawType)) {
return conversionService.convert(source, rawType);
}
if (SecretDocument.class.isAssignableFrom(rawType)) {
return (S) source;
}
if (Map.class.isAssignableFrom(rawType) && secretDocument != null) {
return (S) secretDocument.getBody();
}
if (typeToUse.isMap() && secretDocument != null) {
return (S) readMap(typeToUse, secretDocument.getBody());
}
if (typeToUse.equals(ClassTypeInformation.OBJECT)) {
return (S) source;
}
return read(
(VaultPersistentEntity<S>) mappingContext
.getRequiredPersistentEntity(typeToUse),
secretDocument);
}
示例5: writeMapInternal
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Writes the given {@link Map} to the given {@link Map} considering the given
* {@link TypeInformation}.
*
* @param obj must not be {@literal null}.
* @param bson must not be {@literal null}.
* @param propertyType must not be {@literal null}.
* @return
*/
protected Map<String, Object> writeMapInternal(Map<Object, Object> obj,
Map<String, Object> bson, TypeInformation<?> propertyType) {
for (Entry<Object, Object> entry : obj.entrySet()) {
Object key = entry.getKey();
Object val = entry.getValue();
if (conversions.isSimpleType(key.getClass())) {
String simpleKey = key.toString();
if (val == null || conversions.isSimpleType(val.getClass())) {
bson.put(simpleKey, val);
}
else if (val instanceof Collection || val.getClass().isArray()) {
bson.put(
simpleKey,
writeCollectionInternal(asCollection(val),
propertyType.getMapValueType(), new ArrayList<>()));
}
else {
SecretDocumentAccessor nested = new SecretDocumentAccessor(
new SecretDocument());
TypeInformation<?> valueTypeInfo = propertyType.isMap() ? propertyType
.getMapValueType() : ClassTypeInformation.OBJECT;
writeInternal(val, nested, valueTypeInfo);
bson.put(simpleKey, nested.getBody());
}
}
else {
throw new MappingException("Cannot use a complex object as a key value.");
}
}
return bson;
}
示例6: read
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Read an incoming {@link CrateDocument} into the target entity.
*
* @param type the type information of the target entity.
* @param source the document to convert.
* @param parent an optional parent object.
* @param <R> the entity type.
* @return the converted entity.
*/
@SuppressWarnings("unchecked")
protected <R> R read(final TypeInformation<R> type, final CrateDocument source, final Object parent) {
if(source == null) {
return null;
}
TypeInformation<? extends R> typeToUse = typeMapper.readType(source, type);
Class<? extends R> rawType = typeToUse.getType();
if(conversions.hasCustomReadTarget(source.getClass(), rawType)) {
return conversionService.convert(source, rawType);
}
if(typeToUse.isMap()) {
return (R) readMap(typeToUse, source, parent);
}
CratePersistentEntity<R> entity = (CratePersistentEntity<R>) mappingContext.getPersistentEntity(typeToUse);
if(entity == null) {
throw new MappingException("No mapping metadata found for " + rawType.getName());
}
return read(entity, source, parent);
}
示例7: writeMapInternal
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Helper method to write the map into the crate document.
*
* @param source the source object.
* @param sink the target document.
* @param type the type information for the document.
* @return the written crate document.
*/
private CrateDocument writeMapInternal(final Map<Object, Object> source, final CrateDocument sink, final TypeInformation<?> type) {
for(Map.Entry<Object, Object> entry : source.entrySet()) {
Object key = entry.getKey();
Object val = entry.getValue();
if(conversions.isSimpleType(key.getClass())) {
String simpleKey = key.toString();
if(val == null || (conversions.isSimpleType(val.getClass()) && !val.getClass().isArray())) {
writeSimpleInternal(val, sink, simpleKey);
}else if(val instanceof Collection || val.getClass().isArray()) {
sink.put(simpleKey, writeCollectionInternal(asCollection(val), new CrateArray(), type.getMapValueType()));
}else {
CrateDocument document = new CrateDocument();
TypeInformation<?> valueTypeInfo = type.isMap() ? type.getMapValueType() : OBJECT;
writeInternal(val, document, valueTypeInfo);
sink.put(simpleKey, document);
}
} else {
throw new MappingException("Cannot use a complex object as a key value.");
}
}
return sink;
}
示例8: writePropertyInternal
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked" })
protected void writePropertyInternal(@Nullable Object obj,
SecretDocumentAccessor accessor, VaultPersistentProperty prop) {
if (obj == null) {
return;
}
TypeInformation<?> valueType = ClassTypeInformation.from(obj.getClass());
TypeInformation<?> type = prop.getTypeInformation();
if (valueType.isCollectionLike()) {
List<Object> collectionInternal = createCollection(asCollection(obj), prop);
accessor.put(prop, collectionInternal);
return;
}
if (valueType.isMap()) {
Map<String, Object> mapDbObj = createMap((Map<Object, Object>) obj, prop);
accessor.put(prop, mapDbObj);
return;
}
// Lookup potential custom target type
Optional<Class<?>> basicTargetType = conversions.getCustomWriteTarget(obj
.getClass());
if (basicTargetType.isPresent()) {
accessor.put(prop, conversionService.convert(obj, basicTargetType.get()));
return;
}
VaultPersistentEntity<?> entity = isSubtype(prop.getType(), obj.getClass()) ? mappingContext
.getRequiredPersistentEntity(obj.getClass()) : mappingContext
.getRequiredPersistentEntity(type);
SecretDocumentAccessor nested = accessor.writeNested(prop);
writeInternal(obj, nested, entity);
addCustomTypeKeyIfNecessary(ClassTypeInformation.from(prop.getRawType()), obj,
nested);
}