PropertyAccessor myAccessor = PropertyAccessorFactory.forBeanPropertyAccess(object); // a `setSomeProperty()` method will be used myAccessor.setPropertyValue("someProperty", "some value");
PropertyAccessor myAccessor = PropertyAccessorFactory.forDirectFieldAccess(object); // set the property directly, bypassing the mutator (if any) myAccessor.setPropertyValue("someProperty", "some value");
/** * Copies the unmapped properties of the given {@link MappedProperties} from the source object to the target instance. * * @param properties must not be {@literal null}. * @param source must not be {@literal null}. * @param target must not be {@literal null}. */ private static void copyRemainingProperties(MappedProperties properties, Object source, Object target) { PropertyAccessor sourceFieldAccessor = PropertyAccessorFactory.forDirectFieldAccess(source); PropertyAccessor sourcePropertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(source); PropertyAccessor targetFieldAccessor = PropertyAccessorFactory.forDirectFieldAccess(target); PropertyAccessor targetPropertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(target); for (String property : properties.getSpringDataUnmappedProperties()) { // If there's a field we can just copy it. if (targetFieldAccessor.isWritableProperty(property)) { targetFieldAccessor.setPropertyValue(property, sourceFieldAccessor.getPropertyValue(property)); continue; } // Otherwise only copy if there's both a getter and setter. if (targetPropertyAccessor.isWritableProperty(property) && sourcePropertyAccessor.isReadableProperty(property)) { targetPropertyAccessor.setPropertyValue(property, sourcePropertyAccessor.getPropertyValue(property)); } } }
dfa.setPropertyValue("restTemplate", template);
dfa.setPropertyValue("restTemplate", template);
public static void setProperty(Object bean, String name, Object value) { PropertyAccessor wrapper = createAccessor(bean); wrapper.setPropertyValue(name, value); }
/** * {@inheritDoc} * * Delegates to the configured {@link ConversionService} to potentially convert the value to the actual type of the property. */ @Override public void setValue(Object instance, String propertyName, Object value) { if (!isWriteIgnored(instance, propertyName)) { PropertyProxyUtils.getPropertyAccessor(this.conversionService, this.useDirectFieldAccess, instance).setPropertyValue(propertyName, value); } }
paBean.setPropertyValue(key, value); paDirect.setPropertyValue(key, value);
paBean.setPropertyValue(key, value); paDirect.setPropertyValue(key, value);
"All handlers except for the last one in the chain must implement property '" + OUTPUT_CHANNEL_PROPERTY + "' of type 'MessageChannel'"); accessor.setPropertyValue(OUTPUT_CHANNEL_PROPERTY, channel); accessor.setPropertyValue(OUTPUT_CHANNEL_PROPERTY, replyChannel);
private Directory getDirectoryService() { HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jacksonFactory = new JacksonFactory(); GoogleCredential credential = getGoogleCredential(); PropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(credential); accessor.setPropertyValue("serviceAccountUser", config.getAdminUsername()); accessor.setPropertyValue("serviceAccountScopes", SERVICE_ACCOUNT_SCOPES); return new Directory.Builder(httpTransport, jacksonFactory, credential) .setApplicationName("Spinnaker-Fiat") .build(); }
private Directory getDirectoryService() { HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jacksonFactory = new JacksonFactory(); GoogleCredential credential = getGoogleCredential(); PropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(credential); accessor.setPropertyValue("serviceAccountUser", config.getAdminUsername()); accessor.setPropertyValue("serviceAccountScopes", SERVICE_ACCOUNT_SCOPES); return new Directory.Builder(httpTransport, jacksonFactory, credential) .setApplicationName("Spinnaker-Fiat") .build(); }
/** * Copies the unmapped properties of the given {@link MappedProperties} from the source object to the target instance. * * @param properties must not be {@literal null}. * @param source must not be {@literal null}. * @param target must not be {@literal null}. */ private static void copyRemainingProperties(MappedProperties properties, Object source, Object target) { PropertyAccessor sourceFieldAccessor = PropertyAccessorFactory.forDirectFieldAccess(source); PropertyAccessor sourcePropertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(source); PropertyAccessor targetFieldAccessor = PropertyAccessorFactory.forDirectFieldAccess(target); PropertyAccessor targetPropertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(target); for (String property : properties.getSpringDataUnmappedProperties()) { // If there's a field we can just copy it. if (targetFieldAccessor.isWritableProperty(property)) { targetFieldAccessor.setPropertyValue(property, sourceFieldAccessor.getPropertyValue(property)); continue; } // Otherwise only copy if there's both a getter and setter. if (targetPropertyAccessor.isWritableProperty(property) && sourcePropertyAccessor.isReadableProperty(property)) { targetPropertyAccessor.setPropertyValue(property, sourcePropertyAccessor.getPropertyValue(property)); } } }