/** * Create a new empty accessor. Wrapped instance needs to be set afterwards. * @param registerDefaultEditors whether to register default editors * (can be suppressed if the accessor won't need any type conversion) * @see #setWrappedInstance */ protected AbstractNestablePropertyAccessor(boolean registerDefaultEditors) { if (registerDefaultEditors) { registerDefaultEditors(); } this.typeConverterDelegate = new TypeConverterDelegate(this); }
editor = findDefaultEditor(requiredType); convertedValue = doConvertValue(oldValue, convertedValue, requiredType, editor); convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue); return (T) convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType()); convertedValue = convertToTypedCollection( (Collection<?>) convertedValue, propertyName, requiredType, typeDescriptor); standardConversion = true; convertedValue = convertToTypedMap( (Map<?, ?>) convertedValue, propertyName, requiredType, typeDescriptor); standardConversion = true; convertedValue = attemptToConvertStringToEnum(requiredType, trimmedValue, convertedValue); standardConversion = true;
if (!approximable && !canCreateCopy(requiredType)) { if (logger.isDebugEnabled()) { logger.debug("Custom Map type [" + original.getClass().getName() + Object key = entry.getKey(); Object value = entry.getValue(); String keyedPropertyName = buildKeyedPropertyName(propertyName, key); Object convertedKey = convertIfNecessary(keyedPropertyName, null, key, (keyType != null ? keyType.getType() : null), keyType); Object convertedValue = convertIfNecessary(keyedPropertyName, null, value, (valueType!= null ? valueType.getType() : null), valueType); try {
int i = 0; for (Iterator<?> it = coll.iterator(); it.hasNext(); i++) { Object value = convertIfNecessary( buildIndexedPropertyName(propertyName, i), null, it.next(), componentType); Array.set(result, i, value); Object result = Array.newInstance(componentType, arrayLength); for (int i = 0; i < arrayLength; i++) { Object value = convertIfNecessary( buildIndexedPropertyName(propertyName, i), null, Array.get(input, i), componentType); Array.set(result, i, value); Object value = convertIfNecessary( buildIndexedPropertyName(propertyName, 0), null, input, componentType); Array.set(result, 0, value); return result;
if (!approximable && !canCreateCopy(requiredType)) { if (logger.isDebugEnabled()) { logger.debug("Custom Collection type [" + original.getClass().getName() + for (; it.hasNext(); i++) { Object element = it.next(); String indexedPropertyName = buildIndexedPropertyName(propertyName, i); Object convertedElement = convertIfNecessary(indexedPropertyName, null, element, (elementType != null ? elementType.getType() : null) , elementType); try {
/** * Convert the value to the required type for the specified property. * @param propertyName name of the property * @param oldValue the previous value, if available (may be {@code null}) * @param newValue the proposed new value * @param requiredType the type we must convert to * (or {@code null} if not known, for example in case of a collection element) * @return the new value, possibly the result of type conversion * @throws IllegalArgumentException if type conversion failed */ @Nullable public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue, @Nullable Class<T> requiredType) throws IllegalArgumentException { return convertIfNecessary(propertyName, oldValue, newValue, requiredType, TypeDescriptor.valueOf(requiredType)); }
return doConvertTextValue(oldValue, newTextValue, editor);
Object key = entry.getKey(); Object value = entry.getValue(); String keyedPropertyName = buildKeyedPropertyName(propertyName, key); Object convertedKey = convertIfNecessary(keyedPropertyName, null, key, (keyType != null ? keyType.getType() : null), keyType);
if (!approximable && !canCreateCopy(requiredType)) { if (logger.isDebugEnabled()) { logger.debug("Custom Collection type [" + original.getClass().getName() + for (; it.hasNext(); i++) { Object element = it.next(); String indexedPropertyName = buildIndexedPropertyName(propertyName, i); Object convertedElement = convertIfNecessary(indexedPropertyName, null, element, (elementType != null ? elementType.getType() : null) , elementType); try {
@Nullable @Override public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable TypeDescriptor typeDescriptor) throws TypeMismatchException { Assert.state(this.typeConverterDelegate != null, "No TypeConverterDelegate"); try { return this.typeConverterDelegate.convertIfNecessary(null, null, value, requiredType, typeDescriptor); } catch (ConverterNotFoundException | IllegalStateException ex) { throw new ConversionNotSupportedException(value, requiredType, ex); } catch (ConversionException | IllegalArgumentException ex) { throw new TypeMismatchException(value, requiredType, ex); } }
int i = 0; for (Iterator<?> it = coll.iterator(); it.hasNext(); i++) { Object value = convertIfNecessary( buildIndexedPropertyName(propertyName, i), null, it.next(), componentType); Array.set(result, i, value); Object result = Array.newInstance(componentType, arrayLength); for (int i = 0; i < arrayLength; i++) { Object value = convertIfNecessary( buildIndexedPropertyName(propertyName, i), null, Array.get(input, i), componentType); Array.set(result, i, value); Object value = convertIfNecessary( buildIndexedPropertyName(propertyName, 0), null, input, componentType); Array.set(result, 0, value); return result;
return doConvertTextValue(oldValue, newTextValue, editor);
editor = findDefaultEditor(requiredType); convertedValue = doConvertValue(oldValue, convertedValue, requiredType, editor); convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue); return (T) convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType()); convertedValue = convertToTypedCollection( (Collection<?>) convertedValue, propertyName, requiredType, typeDescriptor); standardConversion = true; convertedValue = convertToTypedMap( (Map<?, ?>) convertedValue, propertyName, requiredType, typeDescriptor); standardConversion = true; convertedValue = attemptToConvertStringToEnum(requiredType, trimmedValue, convertedValue); standardConversion = true;
if (!approximable && !canCreateCopy(requiredType)) { if (logger.isDebugEnabled()) { logger.debug("Custom Map type [" + original.getClass().getName() + Object key = entry.getKey(); Object value = entry.getValue(); String keyedPropertyName = buildKeyedPropertyName(propertyName, key); Object convertedKey = convertIfNecessary(keyedPropertyName, null, key, (keyType != null ? keyType.getType() : null), keyType); Object convertedValue = convertIfNecessary(keyedPropertyName, null, value, (valueType!= null ? valueType.getType() : null), valueType); try {
if (!approximable && !canCreateCopy(requiredType)) { if (logger.isDebugEnabled()) { logger.debug("Custom Collection type [" + original.getClass().getName() + for (; it.hasNext(); i++) { Object element = it.next(); String indexedPropertyName = buildIndexedPropertyName(propertyName, i); Object convertedElement = convertIfNecessary(indexedPropertyName, null, element, (elementType != null ? elementType.getType() : null) , elementType); try {
@Nullable private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue, @Nullable Class<?> requiredType, @Nullable TypeDescriptor td) throws TypeMismatchException { Assert.state(this.typeConverterDelegate != null, "No TypeConverterDelegate"); try { return this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, newValue, requiredType, td); } catch (ConverterNotFoundException | IllegalStateException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(getRootInstance(), this.nestedPath + propertyName, oldValue, newValue); throw new ConversionNotSupportedException(pce, requiredType, ex); } catch (ConversionException | IllegalArgumentException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(getRootInstance(), this.nestedPath + propertyName, oldValue, newValue); throw new TypeMismatchException(pce, requiredType, ex); } }
/** * Set a bean instance to hold, without any unwrapping of {@link java.util.Optional}. * @param object the actual target object * @since 4.3 * @see #setWrappedInstance(Object) */ public void setBeanInstance(Object object) { this.wrappedObject = object; this.rootObject = object; this.typeConverterDelegate = new TypeConverterDelegate(this, this.wrappedObject); setIntrospectionClass(object.getClass()); }
int i = 0; for (Iterator it = coll.iterator(); it.hasNext(); i++) { Object value = convertIfNecessary( buildIndexedPropertyName(propertyName, i), null, it.next(), componentType); Array.set(result, i, value); Object result = Array.newInstance(componentType, arrayLength); for (int i = 0; i < arrayLength; i++) { Object value = convertIfNecessary( buildIndexedPropertyName(propertyName, i), null, Array.get(input, i), componentType); Array.set(result, i, value); Object value = convertIfNecessary( buildIndexedPropertyName(propertyName, 0), null, input, componentType); Array.set(result, 0, value); return result;
return doConvertTextValue(oldValue, newTextValue, editor); return doConvertTextValue(oldValue, newTextValue, editor);
editor = findDefaultEditor(requiredType, typeDescriptor); convertedValue = doConvertValue(oldValue, convertedValue, requiredType, editor); convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue); return (T) convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType()); convertedValue = convertToTypedCollection( (Collection) convertedValue, propertyName, requiredType, typeDescriptor); convertedValue = convertToTypedMap( (Map) convertedValue, propertyName, requiredType, typeDescriptor); convertedValue = attemptToConvertStringToEnum(requiredType, trimmedValue, convertedValue);