@Override public Object prepare(@Nullable Object value) { if (!ObjectUtils.isArray(value)) { return value; } int length = Array.getLength(value); Collection<Object> result = new ArrayList<>(length); for (int i = 0; i < length; i++) { result.add(Array.get(value, i)); } return result; } }
@Override public Object getValue(@Nullable String name) { Object value = this.delegate.getValue(name); if (ObjectUtils.isArray(value)) { value = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(value)); } return value; } }
/** * Returns the given argument as {@link Collection} which means it will return it as is if it's a * {@link Collections}, turn an array into an {@link ArrayList} or simply wrap any other value into a single element * {@link Collections}. * * @param value the value to be converted to a {@link Collection}. * @return the object itself as a {@link Collection} or a {@link Collection} constructed from the value. */ @Nullable private static Collection<?> toCollection(@Nullable Object value) { if (value == null) { return null; } if (value instanceof Collection) { return (Collection<?>) value; } if (ObjectUtils.isArray(value)) { return Arrays.asList(ObjectUtils.toObjectArray(value)); } return Collections.singleton(value); } }
@Override public Object getValue(@Nullable String name) { Object value = this.delegate.getValue(name); if (ObjectUtils.isArray(value)) { value = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(value)); } return value; } }
/** * 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; }
@Override protected Object convert(AggregationExpressionTransformationContext<ExpressionNode> context) { Object value = context.getCurrentNode().getValue(); return ObjectUtils.isArray(value) ? Arrays.asList(ObjectUtils.toObjectArray(value)) : value; }
boolean operandIsArray = ObjectUtils.isArray(operand);
@Override public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) { // Create field error with the exceptions's code, e.g. "typeMismatch". String field = ex.getPropertyName(); Assert.state(field != null, "No field in exception"); String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field); Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field); Object rejectedValue = ex.getValue(); if (ObjectUtils.isArray(rejectedValue)) { rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue)); } FieldError error = new FieldError(bindingResult.getObjectName(), field, rejectedValue, true, codes, arguments, ex.getLocalizedMessage()); error.wrap(ex); bindingResult.addError(error); }
!(convertedValue instanceof Collection || ObjectUtils.isArray(convertedValue))) { pv.setConvertedValue(convertedValue); deepCopy.add(pv);
if (operand instanceof Iterable || ObjectUtils.isArray(operand)) { Iterable<?> data = (operand instanceof Iterable ? (Iterable<?>) operand : Arrays.asList(ObjectUtils.toObjectArray(operand)));
@Override public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) { // Create field error with the exceptions's code, e.g. "typeMismatch". String field = ex.getPropertyName(); Assert.state(field != null, "No field in exception"); String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field); Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field); Object rejectedValue = ex.getValue(); if (ObjectUtils.isArray(rejectedValue)) { rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue)); } FieldError error = new FieldError(bindingResult.getObjectName(), field, rejectedValue, true, codes, arguments, ex.getLocalizedMessage()); error.wrap(ex); bindingResult.addError(error); }
!(convertedValue instanceof Collection || ObjectUtils.isArray(convertedValue))) { pv.setConvertedValue(convertedValue); deepCopy.add(pv);
boolean operandIsArray = ObjectUtils.isArray(operand);
if (operand instanceof Iterable || ObjectUtils.isArray(operand)) { Iterable<?> data = (operand instanceof Iterable ? (Iterable<?>) operand : Arrays.asList(ObjectUtils.toObjectArray(operand)));
private void setMessageHeader(Map<String, Object> target, String name, Object value) { if (ObjectUtils.isArray(value)) { Object[] values = ObjectUtils.toObjectArray(value); if (!ObjectUtils.isEmpty(values)) { if (values.length == 1) { target.put(name, values); } else { target.put(name, values[0]); } } } else if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { if (values.size() == 1) { target.put(name, values.iterator().next()); } else { target.put(name, values); } } } else if (value != null) { target.put(name, value); } }
/** * 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; }
@Override protected Object convert(AggregationExpressionTransformationContext<ExpressionNode> context) { Object value = context.getCurrentNode().getValue(); return ObjectUtils.isArray(value) ? Arrays.asList(ObjectUtils.toObjectArray(value)) : value; }
!(convertedValue instanceof Collection || ObjectUtils.isArray(convertedValue))) { pv.setConvertedValue(convertedValue); deepCopy.add(pv);
@Override public Object prepare(@Nullable Object value) { if (!ObjectUtils.isArray(value)) { return value; } int length = Array.getLength(value); Collection<Object> result = new ArrayList<>(length); for (int i = 0; i < length; i++) { result.add(Array.get(value, i)); } return result; } }
private void putProperties(String name, Object value, Map<String, Object> properties) { if (ObjectUtils.isArray(value)) { Object[] array = ObjectUtils.toObjectArray(value); for (int i = 0; i < array.length; i++) { properties.put(name + "[" + i + "]", array[i]); } } else { properties.put(name, value); } }