/** * Returns the {@link BeanWrapper} that this instance uses. * Creates a new one if none existed before. * @see #createBeanWrapper() */ @Override public final ConfigurablePropertyAccessor getPropertyAccessor() { if (this.beanWrapper == null) { this.beanWrapper = createBeanWrapper(); this.beanWrapper.setExtractOldValueForEditor(true); this.beanWrapper.setAutoGrowNestedPaths(this.autoGrowNestedPaths); this.beanWrapper.setAutoGrowCollectionLimit(this.autoGrowCollectionLimit); } return this.beanWrapper; }
/** * Returns the {@link BeanWrapper} that this instance uses. * Creates a new one if none existed before. * @see #createBeanWrapper() */ @Override public final ConfigurablePropertyAccessor getPropertyAccessor() { if (this.beanWrapper == null) { this.beanWrapper = createBeanWrapper(); this.beanWrapper.setExtractOldValueForEditor(true); this.beanWrapper.setAutoGrowNestedPaths(this.autoGrowNestedPaths); this.beanWrapper.setAutoGrowCollectionLimit(this.autoGrowCollectionLimit); } return this.beanWrapper; }
@Test public void testStandardEnumSetWithAutoGrowing() { GenericBean<?> gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setAutoGrowNestedPaths(true); assertNull(gb.getStandardEnumSet()); bw.getPropertyValue("standardEnumSet.class"); assertEquals(0, gb.getStandardEnumSet().size()); }
@Test public void testStandardEnumMapWithAutoGrowing() { GenericBean<?> gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setAutoGrowNestedPaths(true); assertNull(gb.getStandardEnumMap()); bw.setPropertyValue("standardEnumMap[VALUE_1]", 1); assertEquals(1, gb.getStandardEnumMap().size()); assertEquals(new Integer(1), gb.getStandardEnumMap().get(CustomEnum.VALUE_1)); }
@Test public void getPropertyWithOptionalAndAutoGrow() { GetterWithOptional target = new GetterWithOptional(); BeanWrapper accessor = createAccessor(target); accessor.setAutoGrowNestedPaths(true); accessor.setPropertyValue("object.name", "x"); assertEquals("x", target.value.getName()); assertEquals("x", target.getObject().get().getName()); assertEquals("x", accessor.getPropertyValue("object.name")); }
/** * {@inheritDoc} */ @Override public void setAutoGrowNestedPaths(boolean autoGrowNestedPaths) { wrapper.setAutoGrowNestedPaths(autoGrowNestedPaths); }
BeanOne one = new BeanOne(); BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(one); wrapper.setAutoGrowNestedPaths(true); Map<String, Object> map = new HashMap<>(); map.put("fieldOne", "fieldOneValue"); map.put("fieldTwo.fieldOne", "fieldOneValue"); wrapper.setPropertyValues(map); assertEquals("fieldOneValue", one.getFieldOne()); BeanTwo two = one.getFieldTwo(); assertNotNull(two); assertEquals("fieldOneValue", two.getFieldOne();
BeanOne one = new BeanOne(); BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(one); wrapper.setAutoGrowNestedPaths(true); Map<String, Object> map = new HashMap<>(); map.put("fieldOne", "fieldOneValue"); map.put("fieldTwo.fieldOne", "fieldOneValue"); wrapper.setPropertyValues(map); assertEquals("fieldOneValue", one.getFieldOne()); BeanTwo two = one.getFieldTwo(); assertNotNull(two); assertEquals("fieldOneValue", two.getFieldOne();
/** * Injects the properties from the given Map to the given object. Additionally, a bean factory can be passed in for * copying property editors inside the injector. * * @param instance bean instance to configure * @param properties * @param beanFactory */ public static void applyMapOntoInstance(Object instance, Map<String, ?> properties, AbstractBeanFactory beanFactory) { if (properties != null && !properties.isEmpty()) { BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(instance); beanWrapper.setAutoGrowNestedPaths(true); // configure bean wrapper (using method from Spring 2.5.6) if (beanFactory != null) { beanFactory.copyRegisteredEditorsTo(beanWrapper); } for (Iterator<?> iterator = properties.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, ?> entry = (Map.Entry<String, ?>) iterator.next(); String propertyName = entry.getKey(); if (beanWrapper.isWritableProperty(propertyName)) { beanWrapper.setPropertyValue(propertyName, entry.getValue()); } } } }
beanWrapper.setAutoGrowNestedPaths(true); String objectKey = name; if (form.name() != null && name.startsWith(form.name() + ".")) {
beanWrapper.setAutoGrowNestedPaths(true); String objectKey = name; if (form.name() != null && name.startsWith(form.name() + ".")) {
beanWrapper.setAutoGrowNestedPaths(true); String objectKey = name; if (form.name() != null && name.startsWith(form.name() + ".")) {
if(form.value().isDefined()) { BeanWrapper beanWrapper = new BeanWrapperImpl(form.value().get()); beanWrapper.setAutoGrowNestedPaths(true); String objectKey = name; if(form.name() != null && name.startsWith(form.name() + ".")) {
if(form.value().isDefined()) { BeanWrapper beanWrapper = new BeanWrapperImpl(form.value().get()); beanWrapper.setAutoGrowNestedPaths(true); String objectKey = name; if(form.name() != null && name.startsWith(form.name() + ".")) {
/** * Returns the {@link BeanWrapper} that this instance uses. * Creates a new one if none existed before. * @see #createBeanWrapper() */ @Override public final ConfigurablePropertyAccessor getPropertyAccessor() { if (this.beanWrapper == null) { this.beanWrapper = createBeanWrapper(); this.beanWrapper.setExtractOldValueForEditor(true); this.beanWrapper.setAutoGrowNestedPaths(this.autoGrowNestedPaths); this.beanWrapper.setAutoGrowCollectionLimit(this.autoGrowCollectionLimit); } return this.beanWrapper; }
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject); bw.setAutoGrowNestedPaths(true);
if(value.isDefined()) { BeanWrapper beanWrapper = new BeanWrapperImpl(value.get()); beanWrapper.setAutoGrowNestedPaths(true); String objectKey = key; if(rootName != null && key.startsWith(rootName + ".")) { beanWrapper.setAutoGrowNestedPaths(true); try { for(Annotation a: beanWrapper.getPropertyTypeDescriptor(key).getAnnotations()) {
if(value.isDefined()) { BeanWrapper beanWrapper = new BeanWrapperImpl(value.get()); beanWrapper.setAutoGrowNestedPaths(true); String objectKey = key; if(rootName != null && key.startsWith(rootName + ".")) { beanWrapper.setAutoGrowNestedPaths(true); try { for(Annotation a: beanWrapper.getPropertyTypeDescriptor(key).getAnnotations()) {
if (value.isPresent()) { BeanWrapper beanWrapper = new BeanWrapperImpl(value.get()); beanWrapper.setAutoGrowNestedPaths(true); String objectKey = key; if (rootName != null && key.startsWith(rootName + ".")) { beanWrapper.setAutoGrowNestedPaths(true); try { for (Annotation a: beanWrapper.getPropertyTypeDescriptor(key).getAnnotations()) {
wrapper.setConversionService( new RelaxedConversionService(getConversionService())); wrapper.setAutoGrowNestedPaths(true); List<PropertyValue> sortedValues = new ArrayList<>(); Set<String> modifiedNames = new HashSet<>();