Java Code Examples for org.springframework.data.util.TypeInformation#getTypeArguments()
The following examples show how to use
org.springframework.data.util.TypeInformation#getTypeArguments() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpannerPersistentPropertyImpl.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Override public Class<?> getColumnInnerType() { TypeInformation<?> ti = getTypeInformation(); List<TypeInformation<?>> typeParams = ti.getTypeArguments(); if (typeParams.size() != 1) { throw new SpannerDataException("in field '" + getColumnName() + "': Unsupported number of type parameters found: " + typeParams.size() + " Only collections of exactly 1 type parameter are supported."); } return typeParams.get(0).getType(); }
Example 2
Source File: MappingSolrConverter.java From dubbox with Apache License 2.0 | 4 votes |
private Object readWildcardMap(Map<String, ?> source, SolrPersistentProperty property, Object parent, WildcardPosition wildcardPosition) { TypeInformation<?> mapTypeInformation = property.getTypeInformation().getMapValueType(); Class<?> rawMapType = mapTypeInformation.getType(); Class<?> genericTargetType; if (mapTypeInformation.getTypeArguments() != null && !mapTypeInformation.getTypeArguments().isEmpty()) { genericTargetType = mapTypeInformation.getTypeArguments().get(0).getType(); } else { genericTargetType = Object.class; } Map<String, Object> values; if (LinkedHashMap.class.isAssignableFrom(property.getActualType())) { values = new LinkedHashMap<String, Object>(); } else { values = new HashMap<String, Object>(); } for (Map.Entry<String, ?> potentialMatch : source.entrySet()) { String key = potentialMatch.getKey(); if (!wildcardPosition.match(property.getFieldName(), key)) { continue; } if (property.isDynamicProperty()) { key = wildcardPosition.extractName(property.getFieldName(), key); } Object value = potentialMatch.getValue(); if (value instanceof Iterable) { if (rawMapType.isArray() || ClassUtils.isAssignable(rawMapType, value.getClass())) { List<Object> nestedValues = new ArrayList<Object>(); for (Object o : (Iterable<?>) value) { nestedValues.add(readValue(property, o, parent, genericTargetType)); } values.put(key, (rawMapType.isArray() ? nestedValues.toArray() : nestedValues)); } else { throw new IllegalArgumentException( "Incompartible types found. Expected " + rawMapType + " for " + property.getName() + " with name " + property.getFieldName() + ", but found " + value.getClass()); } } else { if (rawMapType.isArray() || ClassUtils.isAssignable(rawMapType, List.class)) { ArrayList<Object> singletonArrayList = new ArrayList<Object>(1); Object read = readValue(property, value, parent, genericTargetType); singletonArrayList.add(read); values.put(key, (rawMapType.isArray() ? singletonArrayList.toArray() : singletonArrayList)); } else { values.put(key, getValue(property, value, parent)); } } } return values.isEmpty() ? null : values; }