/** * Populates the given {@link Collection sink} with converted values from the given {@link Collection source}. * * @param source the collection to create a {@link Collection} for, must not be {@literal null}. * @param type the {@link TypeInformation} to consider or {@literal null} if unknown. * @param sink the {@link Collection} to write to. * @return */ @SuppressWarnings("unchecked") private List<Object> writeCollectionInternal(Collection<?> source, @Nullable TypeInformation<?> type, Collection<?> sink) { TypeInformation<?> componentType = null; List<Object> collection = sink instanceof List ? (List<Object>) sink : new ArrayList<>(sink); if (type != null) { componentType = type.getComponentType(); } for (Object element : source) { Class<?> elementType = element == null ? null : element.getClass(); if (elementType == null || conversions.isSimpleType(elementType)) { collection.add(getPotentiallyConvertedSimpleWrite(element)); } else if (element instanceof Collection || elementType.isArray()) { collection.add(writeCollectionInternal(asCollection(element), componentType, new BasicDBList())); } else { Document document = new Document(); writeInternal(element, document, componentType); collection.add(document); } } return collection; }
/** * Writes the given {@link Collection} using the given {@link MongoPersistentProperty} information. * * @param collection must not be {@literal null}. * @param property must not be {@literal null}. * @return */ protected List<Object> createCollection(Collection<?> collection, MongoPersistentProperty property) { if (!property.isDbReference()) { return writeCollectionInternal(collection, property.getTypeInformation(), new BasicDBList()); } List<Object> dbList = new ArrayList<>(collection.size()); for (Object element : collection) { if (element == null) { continue; } DBRef dbRef = createDBRef(element, property); dbList.add(dbRef); } return dbList; }
writeCollectionInternal((Collection<?>) obj, ClassTypeInformation.LIST, (Collection<?>) bson); return;
} else if (val instanceof Collection || val.getClass().isArray()) { addToMap(bson, simpleKey, writeCollectionInternal(asCollection(val), propertyType.getMapValueType(), new BasicDBList())); } else { Document document = new Document();
/** * Writes the given {@link Collection} using the given {@link MongoPersistentProperty} information. * * @param collection must not be {@literal null}. * @param property must not be {@literal null}. * @return */ protected List<Object> createCollection(Collection<?> collection, MongoPersistentProperty property) { if (!property.isDbReference()) { return writeCollectionInternal(collection, property.getTypeInformation(), new BasicDBList()); } List<Object> dbList = new ArrayList<>(collection.size()); for (Object element : collection) { if (element == null) { continue; } DBRef dbRef = createDBRef(element, property); dbList.add(dbRef); } return dbList; }
/** * Populates the given {@link Collection sink} with converted values from the given {@link Collection source}. * * @param source the collection to create a {@link Collection} for, must not be {@literal null}. * @param type the {@link TypeInformation} to consider or {@literal null} if unknown. * @param sink the {@link Collection} to write to. * @return */ @SuppressWarnings("unchecked") private List<Object> writeCollectionInternal(Collection<?> source, @Nullable TypeInformation<?> type, Collection<?> sink) { TypeInformation<?> componentType = null; List<Object> collection = sink instanceof List ? (List<Object>) sink : new ArrayList<>(sink); if (type != null) { componentType = type.getComponentType(); } for (Object element : source) { Class<?> elementType = element == null ? null : element.getClass(); if (elementType == null || conversions.isSimpleType(elementType)) { collection.add(getPotentiallyConvertedSimpleWrite(element)); } else if (element instanceof Collection || elementType.isArray()) { collection.add(writeCollectionInternal(asCollection(element), componentType, new BasicDBList())); } else { Document document = new Document(); writeInternal(element, document, componentType); collection.add(document); } } return collection; }
writeCollectionInternal((Collection<?>) obj, ClassTypeInformation.LIST, (Collection<?>) bson); return;
} else if (val instanceof Collection || val.getClass().isArray()) { addToMap(bson, simpleKey, writeCollectionInternal(asCollection(val), propertyType.getMapValueType(), new BasicDBList())); } else { Document document = new Document();