List of usage examples for org.springframework.beans ConversionNotSupportedException ConversionNotSupportedException
public ConversionNotSupportedException(@Nullable Object value, @Nullable Class<?> requiredType,
@Nullable Throwable cause)
From source file:org.jdal.ui.bind.DirectFieldAccessor.java
@Override public void setPropertyValue(String propertyName, Object newValue) throws BeansException { Field field = this.fieldMap.get(propertyName); if (field == null) { throw new NotWritablePropertyException(this.target.getClass(), propertyName, "Field '" + propertyName + "' does not exist"); }/*from w ww . j a v a 2 s .co m*/ Object oldValue = null; try { ReflectionUtils.makeAccessible(field); oldValue = field.get(this.target); // jlm - Adapt to simpleTypeConverter Object convertedValue = this.typeConverterDelegate.convertIfNecessary(newValue, field.getType()); field.set(this.target, convertedValue); } catch (ConverterNotFoundException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.target, propertyName, oldValue, newValue); throw new ConversionNotSupportedException(pce, field.getType(), ex); } catch (ConversionException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.target, propertyName, oldValue, newValue); throw new TypeMismatchException(pce, field.getType(), ex); } catch (IllegalStateException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.target, propertyName, oldValue, newValue); throw new ConversionNotSupportedException(pce, field.getType(), ex); } catch (IllegalArgumentException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.target, propertyName, oldValue, newValue); throw new TypeMismatchException(pce, field.getType(), ex); } catch (IllegalAccessException ex) { throw new InvalidPropertyException(this.target.getClass(), propertyName, "Field is not accessible", ex); } }
From source file:com.monarchapis.driver.spring.rest.ApiErrorResponseEntityExceptionHandlerTest.java
@Test public void testConversionNotSupportedException() { performTest(// new ConversionNotSupportedException("test", Object.class, null), // 400, // "conversionNotSupported"); }
From source file:org.jdal.ui.bind.DirectFieldAccessor.java
public <T> T convertIfNecessary(Object value, Class<T> requiredType, MethodParameter methodParam) throws TypeMismatchException { try {/* ww w.jav a 2 s. c o m*/ return this.typeConverterDelegate.convertIfNecessary(value, requiredType, methodParam); } catch (IllegalArgumentException ex) { throw new TypeMismatchException(value, requiredType, ex); } catch (IllegalStateException ex) { throw new ConversionNotSupportedException(value, requiredType, ex); } }
From source file:com.traffitruck.web.HtmlController.java
@RequestMapping(value = "/updateload", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) ModelAndView updateLoad(@ModelAttribute("load") Load load, BindingResult br1, @RequestParam("loadPhoto") byte[] loadPhoto, BindingResult br2, @RequestParam("drivedate") String drivedate, BindingResult br3, @RequestParam("sourceLat") Double sourceLat, BindingResult br4, @RequestParam("sourceLng") Double sourceLng, BindingResult br5, @RequestParam("destinationLat") Double destinationLat, BindingResult br6, @RequestParam("destinationLng") Double destinationLng, BindingResult br7, @RequestParam("loadId") String loadId, BindingResult br8) throws IOException, HttpMediaTypeNotAcceptableException { SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); try {/*w ww .ja va2 s . c o m*/ load.setDriveDate(sdf.parse(drivedate)); } catch (ParseException e) { throw new RuntimeException(e); } load.setId(loadId); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String username = authentication.getName(); load.setUsername(username); if (loadPhoto != null && loadPhoto.length > 0) { load.setLoadPhoto(new Binary(loadPhoto)); } if (sourceLat != null && sourceLng != null) { load.setSourceLocation(new Location(new double[] { sourceLng, sourceLat })); } if (destinationLat != null && destinationLng != null) { load.setDestinationLocation(new Location(new double[] { destinationLng, destinationLat })); } Load oldLoad = dao.getLoadForUserById(loadId, username); if (oldLoad == null) { throw new ConversionNotSupportedException(null, null, null); } // update the load dao.updateLoad(load); asyncServices.triggerAlerts(load); return new ModelAndView("redirect:/myLoads"); }
From source file:net.yasion.common.core.bean.wrapper.impl.ExtendedBeanWrapperImpl.java
private Object convertIfNecessary(String propertyName, Object oldValue, Object newValue, Class<?> requiredType, TypeDescriptor td) throws TypeMismatchException { try {/*from w w w .j av a 2s. c om*/ return this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, newValue, requiredType, td); } catch (ConverterNotFoundException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue); throw new ConversionNotSupportedException(pce, td.getType(), ex); } catch (ConversionException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue); throw new TypeMismatchException(pce, requiredType, ex); } catch (IllegalStateException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue); throw new ConversionNotSupportedException(pce, requiredType, ex); } catch (IllegalArgumentException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue); throw new TypeMismatchException(pce, requiredType, ex); } }
From source file:org.nextframework.controller.ExtendedBeanWrapper.java
private <T> T doConvert(Object value, Class<T> requiredType, MethodParameter methodParam, Field field) throws TypeMismatchException { try {//from w ww. j av a2 s . co m if (field != null) { return (T) doTypeConversionIfNecessary(value, requiredType); } else { return (T) doTypeConversionIfNecessary(value, requiredType); } } catch (ConverterNotFoundException ex) { throw new ConversionNotSupportedException(value, requiredType, ex); } catch (ConversionException ex) { throw new TypeMismatchException(value, requiredType, ex); } catch (IllegalStateException ex) { throw new ConversionNotSupportedException(value, requiredType, ex); } catch (IllegalArgumentException ex) { throw new TypeMismatchException(value, requiredType, ex); } }
From source file:org.springframework.beans.AbstractNestablePropertyAccessor.java
@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 {// w w w. ja v a 2 s.c om 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); } }