org.springframework.beans.NullValueInNestedPathException Java Examples
The following examples show how to use
org.springframework.beans.NullValueInNestedPathException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataBinderTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testBindingNoErrorsWithInvalidField() { TestBean rod = new TestBean(); DataBinder binder = new DataBinder(rod, "person"); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Rod"); pvs.add("spouse.age", 32); try { binder.bind(pvs); fail("Should have thrown NullValueInNestedPathException"); } catch (NullValueInNestedPathException ex) { // expected } }
Example #2
Source File: DataBinderTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testBindingNoErrorsWithInvalidField() { TestBean rod = new TestBean(); DataBinder binder = new DataBinder(rod, "person"); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Rod"); pvs.add("spouse.age", 32); try { binder.bind(pvs); fail("Should have thrown NullValueInNestedPathException"); } catch (NullValueInNestedPathException ex) { // expected } }
Example #3
Source File: DataBinderTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testBindingNoErrorsWithInvalidField() throws Exception { TestBean rod = new TestBean(); DataBinder binder = new DataBinder(rod, "person"); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Rod"); pvs.add("spouse.age", 32); try { binder.bind(pvs); fail("Should have thrown NullValueInNestedPathException"); } catch (NullValueInNestedPathException ex) { // expected } }
Example #4
Source File: CukeUtils.java From objectlabkit with Apache License 2.0 | 6 votes |
public static <T> T copyFieldValues(final List<String> fieldsToCopy, final T source, final Class<T> typeOfT) { try { final BeanWrapper src = new BeanWrapperImpl(source); final BeanWrapper target = new BeanWrapperImpl(typeOfT.newInstance()); fieldsToCopy.forEach(t -> { try { Object propertyValue = src.getPropertyValue(t); if (propertyValue instanceof String) { propertyValue = ((String) propertyValue).trim(); } target.setPropertyValue(t, propertyValue); } catch (final NullValueInNestedPathException ignore) { } }); return (T) target.getWrappedInstance(); } catch (InstantiationException | IllegalAccessException e) { return null; } }
Example #5
Source File: UifBeanWrapper.java From rice with Educational Community License v2.0 | 6 votes |
/** * Returns the value for the given property growing nested paths depending on the parameter. * * @param propertyName name of the property to get value for * @param autoGrowNestedPaths whether nested paths should be grown (initialized if null) * @return value for property */ protected Object getPropertyValue(String propertyName, boolean autoGrowNestedPaths) { setAutoGrowNestedPaths(autoGrowNestedPaths); Object value = null; try { value = super.getPropertyValue(propertyName); } catch (NullValueInNestedPathException e) { // swallow null values in path and return null as the value } catch (InvalidPropertyException e1) { if (!(e1.getRootCause() instanceof NullValueInNestedPathException)) { throw e1; } } return value; }
Example #6
Source File: DataObjectWrapperBaseTest.java From rice with Educational Community License v2.0 | 6 votes |
@Test public void testGetPropertyValueNullSafe() { DataObject dataObject = new DataObject("a", "b", 3, "one"); DataObjectWrapper<DataObject> wrap = new DataObjectWrapperImpl<DataObject>(dataObject, dataObjectMetadata, dataObjectService, referenceLinker); assertNull(wrap.getPropertyValue("dataObject2")); //wrap.setPropertyValue("dataObject2.dataObject3", new DataObject3()); // assert that a NullValueInNestedPathException is thrown try { wrap.getPropertyValue("dataObject2.dataObject3"); fail("NullValueInNestedPathException should have been thrown"); } catch (NullValueInNestedPathException e) { // this should be thrown! } // now do a null-safe check assertNull(wrap.getPropertyValueNullSafe("dataObject2.dataObject3")); }
Example #7
Source File: DataBinderFieldAccessTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void nestedBindingWithDisabledAutoGrow() throws Exception { FieldAccessBean rod = new FieldAccessBean(); DataBinder binder = new DataBinder(rod, "person"); binder.setAutoGrowNestedPaths(false); binder.initDirectFieldAccess(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("spouse.name", "Kerry")); assertThatExceptionOfType(NullValueInNestedPathException.class).isThrownBy(() -> binder.bind(pvs)); }
Example #8
Source File: DataBinderFieldAccessTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void nestedBindingWithDisabledAutoGrow() throws Exception { FieldAccessBean rod = new FieldAccessBean(); DataBinder binder = new DataBinder(rod, "person"); binder.setAutoGrowNestedPaths(false); binder.initDirectFieldAccess(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("spouse.name", "Kerry")); thrown.expect(NullValueInNestedPathException.class); binder.bind(pvs); }
Example #9
Source File: DataBinderFieldAccessTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void nestedBindingWithDisabledAutoGrow() throws Exception { FieldAccessBean rod = new FieldAccessBean(); DataBinder binder = new DataBinder(rod, "person"); binder.setAutoGrowNestedPaths(false); binder.initDirectFieldAccess(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("spouse.name", "Kerry")); thrown.expect(NullValueInNestedPathException.class); binder.bind(pvs); }
Example #10
Source File: UifViewBeanWrapper.java From rice with Educational Community License v2.0 | 5 votes |
/** * Checks whether the given property is secure. * * @param wrappedClass class the property is associated with * @param propertyPath path to the property * @return boolean true if the property is secure, false if not */ protected boolean isSecure(Class<?> wrappedClass, String propertyPath) { if (KRADUtils.isSecure(propertyPath, wrappedClass)) { return true; } // since this is part of a set, we want to make sure nested paths grow setAutoGrowNestedPaths(true); BeanWrapperImpl beanWrapper; try { beanWrapper = getBeanWrapperForPropertyPath(propertyPath); } catch (NotReadablePropertyException | NullValueInNestedPathException e) { LOG.debug("Bean wrapper was not found for " + propertyPath + ", but since it cannot be accessed it will not be set as secure.", e); return false; } if (org.apache.commons.lang.StringUtils.isNotBlank(beanWrapper.getNestedPath())) { PropertyTokenHolder tokens = getPropertyNameTokens(propertyPath); String nestedPropertyPath = org.apache.commons.lang.StringUtils.removeStart(tokens.canonicalName, beanWrapper.getNestedPath()); return isSecure(beanWrapper.getWrappedClass(), nestedPropertyPath); } return false; }
Example #11
Source File: DataObjectWrapperBase.java From rice with Educational Community License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Object getPropertyValueNullSafe(String propertyName) throws BeansException { try { return getPropertyValue(propertyName); } catch (NullValueInNestedPathException e) { return null; } }