} else if (val instanceof Collection || val.getClass().isArray()) { addToMap(bson, simpleKey, writeCollectionInternal(asCollection(val), propertyType.getMapValueType(), new BasicDBList())); } else { Document document = new Document(); TypeInformation<?> valueTypeInfo = propertyType.isMap() ? propertyType.getMapValueType() : ClassTypeInformation.OBJECT; writeInternal(val, document, valueTypeInfo);
TypeInformation<?> valueType = type.getMapValueType();
: (targetProperty.isMap() ? (targetProperty.getTypeInformation().getMapValueType() != null ? targetProperty.getTypeInformation().getRequiredMapValueType() : ClassTypeInformation.OBJECT) : targetProperty.getTypeInformation().getActualType());
TypeInformation<?> valueType = type.getMapValueType();
} else if (val instanceof Collection || val.getClass().isArray()) { addToMap(bson, simpleKey, writeCollectionInternal(asCollection(val), propertyType.getMapValueType(), new BasicDBList())); } else { Document document = new Document(); TypeInformation<?> valueTypeInfo = propertyType.isMap() ? propertyType.getMapValueType() : ClassTypeInformation.OBJECT; writeInternal(val, document, valueTypeInfo);
TypeInformation<?> valueType = type.getMapValueType();
private TypeInformation<?> getNonNullMapValueType(final TypeInformation<?> type) { final TypeInformation<?> valueType = type.getMapValueType(); return valueType != null ? valueType : ClassTypeInformation.OBJECT; }
private TypeInformation<?> getNonNullMapValueType(final TypeInformation<?> type) { final TypeInformation<?> valueType = type.getMapValueType(); return valueType != null ? valueType : ClassTypeInformation.OBJECT; }
/** * Will return the type of the value in case the underlying type is a {@link java.util.Map} or throw * {@link IllegalStateException} if the map value type cannot be resolved. * * @return * @throws IllegalStateException if the map value type cannot be resolved, usually due to the current * {@link java.util.Map} type being a raw one. * @since 2.0 */ default TypeInformation<?> getRequiredMapValueType() { TypeInformation<?> mapValueType = getMapValueType(); if (mapValueType != null) { return mapValueType; } throw new IllegalStateException(String.format("Can't resolve required map value type for %s!", getType())); }
private Map<String, Object> convertMap(final Map<Object, Object> source, final TypeInformation<?> type) { Assert.notNull(source, "Given map must not be null!"); Assert.notNull(type, "Given type must not be null!"); return source.entrySet().stream().collect(HashMap::new, (m, e) -> { Object key = e.getKey(); Object value = e.getValue(); if (!conversions.isSimpleType(key.getClass())) { throw new MappingException("Cannot use a complex object as a key value."); } String simpleKey = key.toString(); Object convertedValue = getValueToWrite(value, type.getMapValueType()); m.put(simpleKey, convertedValue); }, HashMap::putAll); }
@Nullable @Override public Class<?> getMapValueType() { if (isMap()) { TypeInformation<?> mapValueType = information.getMapValueType(); if (mapValueType != null) { return mapValueType.getType(); } } return null; }
public Class<?> getMapValueType() { return isMap() ? information.getMapValueType().getType() : null; }
private <R> R convertMap(Map<String, Object> source, TypeInformation<?> propertyType) { Class<?> mapClass = propertyType.getType(); TypeInformation<?> keyType = propertyType.getComponentType(); Class<?> keyClass = keyType == null ? null : keyType.getType(); TypeInformation<?> mapValueType = propertyType.getMapValueType(); Map<Object, Object> converted = CollectionFactory.createMap(mapClass, keyClass, source.keySet().size()); source.entrySet() .forEach((e) -> { Object key = (keyClass != null) ? conversionService.convert(e.getKey(), keyClass) : e.getKey(); Object value = readValue(e.getValue(), mapValueType); converted.put(key, value); }); return (R) convertIfNeeded(converted, propertyType.getType()); }
/** * Reads the given {@link Map} into a map of the given {@link TypeInformation}. * * @param source must not be {@literal null}. * @param targetType must not be {@literal null}. * @return the converted {@link Collection} or array, will never be {@literal null}. */ @SuppressWarnings({ "rawtypes", "unchecked" }) private Object readMapInternal(Map<Object, Object> source, TypeInformation<?> targetType) { Assert.notNull(targetType, "Target type must not be null"); TypeInformation<?> keyType = targetType.getComponentType(); TypeInformation<?> valueType = targetType.getMapValueType(); Class<?> rawKeyType = keyType != null ? keyType.getType() : null; Map<Object, Object> map = CollectionFactory.createMap(resolveMapType(targetType), rawKeyType, source.size()); if (source.isEmpty()) { return map; } for (Entry<Object, Object> entry : source.entrySet()) { Object key = entry.getKey(); if (key != null && rawKeyType != null && !rawKeyType.isAssignableFrom(key.getClass())) { key = convertReadValue(key, keyType); } Object value = entry.getValue(); map.put(key, convertReadValue(value, valueType)); } return map; }
TypeInformation<?> valueType = type.getMapValueType();
writeSimpleInternal(val, target, simpleKey); } else if (val instanceof Collection || val.getClass().isArray()) { target.put(simpleKey, writeCollectionInternal(asCollection(val), new CouchbaseList(conversions.getSimpleTypeHolder()), type.getMapValueType())); } else { CouchbaseDocument embeddedDoc = new CouchbaseDocument(); TypeInformation<?> valueTypeInfo = type.isMap() ? type.getMapValueType() : ClassTypeInformation.OBJECT; writeInternal(val, embeddedDoc, valueTypeInfo); target.put(simpleKey, embeddedDoc);
writeSimpleInternal(val, target, simpleKey); } else if (val instanceof Collection || val.getClass().isArray()) { target.put(simpleKey, writeCollectionInternal(asCollection(val), new CouchbaseList(conversions.getSimpleTypeHolder()), type.getMapValueType())); } else { CouchbaseDocument embeddedDoc = new CouchbaseDocument(); TypeInformation<?> valueTypeInfo = type.isMap() ? type.getMapValueType() : ClassTypeInformation.OBJECT; writeInternal(val, embeddedDoc, valueTypeInfo); target.put(simpleKey, embeddedDoc);
TypeInformation<?> valueType = type.getMapValueType(); if (value instanceof CouchbaseDocument) { map.put(key, read(valueType, (CouchbaseDocument) value, parent));
TypeInformation<?> valueType = type.getMapValueType(); if (value instanceof CouchbaseDocument) { map.put(key, read(valueType, (CouchbaseDocument) value, parent));
@SuppressWarnings("all") private DataType getMapDataType(TypeInformation<?> typeInformation, DataTypeProvider dataTypeProvider) { TypeInformation<?> keyTypeInformation = typeInformation.getComponentType(); TypeInformation<?> valueTypeInformation = typeInformation.getMapValueType(); DataType keyType = getDataTypeWithUserTypeFactory(keyTypeInformation, dataTypeProvider, () -> { DataType type = doGetDataType(keyTypeInformation.getType(), keyTypeInformation.getType()); if (type != null) { return type; } throw new MappingException(String.format("Cannot resolve key type for [%s]", typeInformation)); }); DataType valueType = getDataTypeWithUserTypeFactory(valueTypeInformation, dataTypeProvider, () -> { DataType type = doGetDataType(valueTypeInformation.getType(), valueTypeInformation.getType()); if (type != null) { return type; } throw new MappingException("Cannot resolve value type for " + typeInformation + "."); }); return DataType.map(keyType, valueType); }