/** * Checks whether we have a custom conversion registered for the given value into an arbitrary simple Mongo type. * Returns the converted value if so. If not, we perform special enum handling or simply return the value as is. * * @param value * @return */ @Nullable private Object getPotentiallyConvertedSimpleWrite(@Nullable Object value) { if (value == null) { return null; } Optional<Class<?>> customTarget = conversions.getCustomWriteTarget(value.getClass()); if (customTarget.isPresent()) { return conversionService.convert(value, customTarget.get()); } if (ObjectUtils.isArray(value)) { if (value instanceof byte[]) { return value; } return asCollection(value); } return Enum.class.isAssignableFrom(value.getClass()) ? ((Enum<?>) value).name() : value; }
/** * 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; }
} else if (val instanceof Collection || val.getClass().isArray()) { addToMap(bson, simpleKey, writeCollectionInternal(asCollection(val), propertyType.getMapValueType(), new BasicDBList())); } else { Document document = new Document();
List<Object> collectionInternal = createCollection(asCollection(obj), prop); accessor.put(prop, collectionInternal); return;
/** * Checks whether we have a custom conversion registered for the given value into an arbitrary simple Mongo type. * Returns the converted value if so. If not, we perform special enum handling or simply return the value as is. * * @param value * @return */ @Nullable private Object getPotentiallyConvertedSimpleWrite(@Nullable Object value) { if (value == null) { return null; } Optional<Class<?>> customTarget = conversions.getCustomWriteTarget(value.getClass()); if (customTarget.isPresent()) { return conversionService.convert(value, customTarget.get()); } if (ObjectUtils.isArray(value)) { if (value instanceof byte[]) { return value; } return asCollection(value); } return Enum.class.isAssignableFrom(value.getClass()) ? ((Enum<?>) value).name() : value; }
/** * 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; }
} else if (val instanceof Collection || val.getClass().isArray()) { addToMap(bson, simpleKey, writeCollectionInternal(asCollection(val), propertyType.getMapValueType(), new BasicDBList())); } else { Document document = new Document();
List<Object> collectionInternal = createCollection(asCollection(obj), prop); accessor.put(prop, collectionInternal); return;