本文整理汇总了Java中org.springframework.data.util.TypeInformation.getType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeInformation.getType方法的具体用法?Java TypeInformation.getType怎么用?Java TypeInformation.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.util.TypeInformation
的用法示例。
在下文中一共展示了TypeInformation.getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readValue
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
@Nullable
@SuppressWarnings("unchecked")
private <T> T readValue(Object value, TypeInformation<?> type) {
Class<?> rawType = type.getType();
if (conversions.hasCustomReadTarget(value.getClass(), rawType)) {
return (T) conversionService.convert(value, rawType);
}
else if (value instanceof List) {
return (T) readCollectionOrArray(type, (List) value);
}
else if (value instanceof Map) {
return (T) read(type, (Map) value);
}
else {
return (T) getPotentiallyConvertedSimpleRead(value, rawType);
}
}
示例2: read
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected <S extends Object> S read(TypeInformation<S> targetTypeInformation, Map<String, ?> source) {
if (source == null) {
return null;
}
Assert.notNull(targetTypeInformation);
Class<S> rawType = targetTypeInformation.getType();
// in case there's a custom conversion for the document
if (hasCustomReadTarget(source.getClass(), rawType)) {
return convert(source, rawType);
}
SolrPersistentEntity<S> entity = (SolrPersistentEntity<S>) mappingContext.getPersistentEntity(rawType);
return read(entity, source, null);
}
示例3: readCollection
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
private Object readCollection(Collection<?> source, TypeInformation<?> type, Object parent) {
Assert.notNull(type);
Class<?> collectionType = type.getType();
if (CollectionUtils.isEmpty(source)) {
return source;
}
collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType : List.class;
Collection<Object> items;
if (type.getType().isArray()) {
items = new ArrayList<Object>();
} else {
items = CollectionFactory.createCollection(collectionType, source.size());
}
TypeInformation<?> componentType = type.getComponentType();
Iterator<?> it = source.iterator();
while (it.hasNext()) {
items.add(readValue(it.next(), componentType, parent));
}
return type.getType().isArray() ? convertItemsToArrayOfType(type, items) : items;
}
示例4: readValue
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Helper method to read the value based on the value type.
*
* @param value the value to convert.
* @param type the type information.
* @param parent the optional parent.
* @param <R> the target type.
* @return the converted object.
*/
@SuppressWarnings("unchecked")
private <R> R readValue(Object value, TypeInformation<?> type, Object parent) {
Class<?> rawType = type.getType();
if(conversions.hasCustomReadTarget(value.getClass(), rawType)) {
return (R) conversionService.convert(value, rawType);
}else if(value instanceof CrateDocument) {
return (R) read(type, (CrateDocument) value, parent);
}else if(value instanceof CrateArray) {
return (R) readCollection(type, (CrateArray) value, parent);
} else {
return (R) getPotentiallyConvertedSimpleRead(value, rawType);
}
}
示例5: readValue
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> T readValue(Object value, TypeInformation<?> type, Object parent) {
if (value == null) {
return null;
}
Assert.notNull(type);
Class<?> rawType = type.getType();
if (hasCustomReadTarget(value.getClass(), rawType)) {
return (T) convert(value, rawType);
}
Object documentValue = null;
if (value instanceof SolrInputField) {
documentValue = ((SolrInputField) value).getValue();
} else {
documentValue = value;
}
if (documentValue instanceof Collection) {
return (T) readCollection((Collection<?>) documentValue, type, parent);
} else if (canConvert(documentValue.getClass(), rawType)) {
return (T) convert(documentValue, rawType);
}
return (T) documentValue;
}
示例6: readCollection
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Object readCollection(Collection<?> source, TypeInformation<?> type, Object parent) {
Assert.notNull(type);
Class<?> collectionType = type.getType();
if (CollectionUtils.isEmpty(source)) {
return source;
}
collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType : List.class;
Collection<Object> items = type.getType().isArray() ? new ArrayList<Object>() : CollectionFactory
.createCollection(collectionType, source.size());
TypeInformation<?> componentType = type.getComponentType();
Iterator<?> it = source.iterator();
while (it.hasNext()) {
items.add(readValue(it.next(), componentType, parent));
}
return type.getType().isArray() ? convertItemsToArrayOfType(type, items) : items;
}
示例7: BasicSpannerPersistentEntity
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
public BasicSpannerPersistentEntity(TypeInformation<T> information) {
super(information);
Class<?> rawType = information.getType();
String fallback = extractTableNameFromClass(rawType);
Table table = this.findAnnotation(Table.class);
if (table != null) {
this.tableName = StringUtils.hasText(table.name()) ? table.name() : fallback;
} else {
this.tableName = fallback;
}
}
示例8: createJpaQuery
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
public Query createJpaQuery(String queryString) {
Class<?> objectType = getQueryMethod().getReturnedObjectType();
//get original proxy query.
Query oriProxyQuery;
//must be hibernate QueryImpl
QueryImpl query;
if (useJpaSpec && getQueryMethod().isQueryForEntity()) {
oriProxyQuery = getEntityManager().createNativeQuery(queryString, objectType);
// QueryImpl query = AopTargetUtils.getTarget(oriProxyQuery);
} else {
oriProxyQuery = getEntityManager().createNativeQuery(queryString);
query = AopTargetUtils.getTarget(oriProxyQuery);
//find generic type
ClassTypeInformation<?> ctif = ClassTypeInformation.from(objectType);
TypeInformation<?> actualType = ctif.getActualType();
if (actualType == null){
actualType = ctif.getRawTypeInformation();
}
Class<?> genericType = actualType.getType();
if (genericType != null && genericType != Void.class) {
QueryBuilder.transform(query.getHibernateQuery(), genericType);
}
}
//return the original proxy query, for a series of JPA actions, e.g.:close em.
return oriProxyQuery;
}
示例9: 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);
}
示例10: readCollectionOrArray
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Reads the given {@link List} into a collection of the given {@link TypeInformation}
* .
*
* @param targetType must not be {@literal null}.
* @param sourceValue must not be {@literal null}.
* @return the converted {@link Collection} or array, will never be {@literal null}.
*/
@Nullable
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object readCollectionOrArray(TypeInformation<?> targetType, List sourceValue) {
Assert.notNull(targetType, "Target type must not be null!");
Class<?> collectionType = targetType.getType();
TypeInformation<?> componentType = targetType.getComponentType() != null ? targetType
.getComponentType() : ClassTypeInformation.OBJECT;
Class<?> rawComponentType = componentType.getType();
collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType
: List.class;
Collection<Object> items = targetType.getType().isArray() ? new ArrayList<>(
sourceValue.size()) : CollectionFactory.createCollection(collectionType,
rawComponentType, sourceValue.size());
if (sourceValue.isEmpty()) {
return getPotentiallyConvertedSimpleRead(items, collectionType);
}
for (Object obj : sourceValue) {
if (obj instanceof Map) {
items.add(read(componentType, (Map) obj));
}
else if (obj instanceof List) {
items.add(readCollectionOrArray(ClassTypeInformation.OBJECT, (List) obj));
}
else {
items.add(getPotentiallyConvertedSimpleRead(obj, rawComponentType));
}
}
return getPotentiallyConvertedSimpleRead(items, targetType.getType());
}
示例11: readValue
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> T readValue(Object value, TypeInformation<?> type, Object parent) {
if (value == null) {
return null;
}
Assert.notNull(type);
Class<?> rawType = type.getType();
if (hasCustomReadTarget(value.getClass(), rawType)) {
return (T) convert(value, rawType);
}
Object documentValue = null;
if (value instanceof SolrInputField) {
documentValue = ((SolrInputField) value).getValue();
} else {
documentValue = value;
}
if (documentValue instanceof Collection) {
return (T) readCollection((Collection<?>) documentValue, type, parent);
} else if (canConvert(documentValue.getClass(), rawType)) {
return (T) convert(documentValue, rawType);
}
return (T) documentValue;
}
示例12: 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);
}
示例13: readMap
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Recursively parses the a map from the source document.
*
* @param type the type information for the document.
* @param source the source document.
* @param parent the optional parent.
* @return the recursively parsed map.
*/
protected Map<Object, Object> readMap(final TypeInformation<?> type, final CrateDocument source, final Object parent) {
notNull(source);
Class<?> mapType = typeMapper.readType(source, type).getType();
Map<Object, Object> map = createMap(mapType, source.keySet().size());
for(Map.Entry<String, Object> entry : source.entrySet()) {
Object key = entry.getKey();
Object value = entry.getValue();
TypeInformation<?> keyTypeInformation = type.getComponentType();
if(keyTypeInformation != null) {
Class<?> keyType = keyTypeInformation.getType();
key = conversionService.convert(key, keyType);
}
TypeInformation<?> valueType = type.getMapValueType();
if(value instanceof CrateDocument) {
map.put(key, read(valueType, (CrateDocument) value, parent));
}else if(value instanceof CrateArray) {
map.put(key, readCollection(valueType, (CrateArray) value, parent));
}else {
Class<?> valueClass = valueType == null ? null : valueType.getType();
map.put(key, getPotentiallyConvertedSimpleRead(value, valueClass));
}
}
return map;
}
示例14: readCollection
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Read a collection from the source object.
*
* @param targetType the target type.
* @param source the list as source.
* @param parent the optional parent.
* @return the converted {@link Collection} or array, will never be {@literal null}.
*/
private Object readCollection(final TypeInformation<?> targetType, final CrateArray source, final Object parent) {
notNull(targetType);
Class<?> collectionType = targetType.getType();
if(source.isEmpty()) {
return getPotentiallyConvertedSimpleRead(new HashSet<Object>(), collectionType);
}
collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType : List.class;
Collection<Object> items = targetType.getType().isArray() ? new ArrayList<Object>(source.size()) :
createCollection(collectionType, source.size());
TypeInformation<?> componentType = targetType.getComponentType();
Class<?> rawComponentType = componentType == null ? null : componentType.getType();
for(Object object : source) {
if(object instanceof CrateDocument) {
items.add(read(componentType, (CrateDocument) object, parent));
}else {
items.add(getPotentiallyConvertedSimpleRead(object, rawComponentType));
}
}
return getPotentiallyConvertedSimpleRead(items, targetType.getType());
}
示例15: addCustomTypeKeyIfNecessary
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Adds custom type information to the given {@link CrateDocument} if necessary.
*
* @param type
* @param value must not be {@literal null}.
* @param document must not be {@literal null}.
*/
protected void addCustomTypeKeyIfNecessary(TypeInformation<?> type, Object value, CrateDocument document) {
TypeInformation<?> actualType = type != null ? type.getActualType() : null;
Class<?> reference = actualType == null ? Object.class : actualType.getType();
Class<?> valueType = getUserClass(value.getClass());
boolean notTheSameClass = !valueType.equals(reference);
if(notTheSameClass) {
typeMapper.writeType(valueType, document);
}
}