本文整理汇总了Java中org.springframework.data.util.TypeInformation类的典型用法代码示例。如果您正苦于以下问题:Java TypeInformation类的具体用法?Java TypeInformation怎么用?Java TypeInformation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TypeInformation类属于org.springframework.data.util包,在下文中一共展示了TypeInformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BasicVaultPersistentEntity
import org.springframework.data.util.TypeInformation; //导入依赖的package包/类
/**
* Creates new {@link BasicVaultPersistentEntity}.
*
* @param information must not be {@literal null}.
* @param fallbackKeySpaceResolver can be {@literal null}.
*/
public BasicVaultPersistentEntity(TypeInformation<T> information,
KeySpaceResolver fallbackKeySpaceResolver) {
super(information, fallbackKeySpaceResolver);
Secret annotation = findAnnotation(Secret.class);
String keyspace = super.getKeySpace();
String secretBackend = "secret";
if (annotation != null) {
if (StringUtils.hasText(annotation.backend())) {
secretBackend = annotation.backend();
}
}
this.secretBackend = secretBackend;
this.keyspace = String.format("%s/%s", secretBackend, keyspace);
}
示例2: 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);
}
}
示例3: write
import org.springframework.data.util.TypeInformation; //导入依赖的package包/类
@Override
public void write(Object source, SecretDocument sink) {
Class<?> entityType = ClassUtils.getUserClass(source.getClass());
TypeInformation<? extends Object> type = ClassTypeInformation.from(entityType);
SecretDocumentAccessor documentAccessor = new SecretDocumentAccessor(sink);
writeInternal(source, documentAccessor, type);
boolean handledByCustomConverter = conversions.hasCustomWriteTarget(entityType,
SecretDocument.class);
if (!handledByCustomConverter) {
typeMapper.writeType(type, sink.getBody());
}
}
示例4: extractTypeInfo
import org.springframework.data.util.TypeInformation; //导入依赖的package包/类
/**
* Obtains the domain type information from the given method parameter. Will
* favor an explicitly registered on through
* {@link QuerydslPredicate#root()} but use the actual type of the method's
* return type as fallback.
*
* @param parameter
* must not be {@literal null}.
* @return
*/
static TypeInformation<?> extractTypeInfo(MethodParameter parameter) {
QuerydslPredicate annotation = parameter.getParameterAnnotation(QuerydslPredicate.class);
if (annotation != null && !Object.class.equals(annotation.root())) {
return ClassTypeInformation.from(annotation.root());
}
Class<?> containingClass = parameter.getContainingClass();
if (ClassUtils.isAssignable(EntityController.class, containingClass)) {
ResolvableType resolvableType = ResolvableType.forClass(containingClass);
return ClassTypeInformation.from(resolvableType.as(EntityController.class).getGeneric(0).resolve());
}
return detectDomainType(ClassTypeInformation.fromReturnTypeOf(parameter.getMethod()));
}
示例5: detectDomainType
import org.springframework.data.util.TypeInformation; //导入依赖的package包/类
private static TypeInformation<?> detectDomainType(TypeInformation<?> source) {
if (source.getTypeArguments().isEmpty()) {
return source;
}
TypeInformation<?> actualType = source.getActualType();
if (source != actualType) {
return detectDomainType(actualType);
}
if (source instanceof Iterable) {
return source;
}
return detectDomainType(source.getComponentType());
}
示例6: writeCollection
import org.springframework.data.util.TypeInformation; //导入依赖的package包/类
/**
* @param keyspace
* @param path
* @param values
* @param typeHint
* @param sink
*/
private void writeCollection(String keyspace, String path, Collection<?> values, TypeInformation<?> typeHint,
RedisData sink) {
if (values == null) {
return;
}
int i = 0;
for (Object o : values) {
String currentPath = path + ".[" + i + "]";
if (conversionService.canConvert(o.getClass(), byte[].class)) {
sink.addDataEntry(toBytes(currentPath), toBytes(o));
} else {
writeInternal(keyspace, currentPath, o, typeHint, sink);
}
i++;
}
}
示例7: 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);
}
示例8: 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;
}
示例9: 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;
}
示例10: writeCollectionInternal
import org.springframework.data.util.TypeInformation; //导入依赖的package包/类
/**
* Helper method to write the internal collection.
*
* @param source the source object.
* @param target the target document.
* @param type the type information for the document.
* @return the created crate list.
*/
private CrateArray writeCollectionInternal(final Collection<?> source, final CrateArray target, final TypeInformation<?> type) {
TypeInformation<?> componentType = type == null ? null : type.getComponentType();
for(Object element : source) {
validateCollectionLikeElement(element);
Class<?> elementType = element == null ? null : element.getClass();
if(elementType == null || conversions.isSimpleType(elementType)) {
target.add(element);
}else {
CrateDocument document = new CrateDocument();
writeInternal(element, document, componentType);
target.add(document);
}
}
return target;
}
示例11: 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);
}
}
示例12: 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());
}
}
}
示例13: 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);
}
}
}
示例14: write
import org.springframework.data.util.TypeInformation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void write(Object source, @SuppressWarnings("rawtypes") Map target) {
if (source == null) {
return;
}
if (hasCustomWriteTarget(source.getClass(), SolrInputDocument.class)
&& canConvert(source.getClass(), SolrInputDocument.class)) {
SolrInputDocument convertedDocument = convert(source, SolrInputDocument.class);
target.putAll(convertedDocument);
return;
}
TypeInformation<? extends Object> type = ClassTypeInformation.from(source.getClass());
write(type, source, target);
}
示例15: 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;
}