congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ConversionFailedException
Code IndexAdd Tabnine to your IDE (free)

How to use
ConversionFailedException
in
org.springframework.core.convert

Best Java code snippets using org.springframework.core.convert.ConversionFailedException (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

private void assertNotPrimitiveTargetType(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (targetType.isPrimitive()) {
    throw new ConversionFailedException(sourceType, targetType, null,
        new IllegalArgumentException("A null value cannot be assigned to a primitive type"));
  }
}
origin: spring-projects/spring-framework

@Test
public void convertListOfNonStringifiable() {
  List<Object> list = Arrays.asList(new TestEntity(1L), new TestEntity(2L));
  assertTrue(conversionService.canConvert(list.getClass(), String.class));
  try {
    conversionService.convert(list, String.class);
  }
  catch (ConversionFailedException ex) {
    assertTrue(ex.getMessage().contains(list.getClass().getName()));
    assertTrue(ex.getCause() instanceof ConverterNotFoundException);
    assertTrue(ex.getCause().getMessage().contains(TestEntity.class.getName()));
  }
}
origin: org.springframework.boot/spring-boot

private String getMessage(BindException cause) {
  ConversionFailedException conversionFailure = findCause(cause,
      ConversionFailedException.class);
  if (conversionFailure != null) {
    return "failed to convert " + conversionFailure.getSourceType() + " to "
        + conversionFailure.getTargetType();
  }
  Throwable failure = cause;
  while (failure.getCause() != null) {
    failure = failure.getCause();
  }
  return (StringUtils.hasText(failure.getMessage()) ? failure.getMessage()
      : cause.getMessage());
}
origin: spring-projects/spring-framework

@Test
public void scalarMapNotGenericSourceField() throws Exception {
  Map<String, String> map = new HashMap<>();
  map.put("1", "9");
  map.put("2", "37");
  TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("notGenericMapSource"));
  TypeDescriptor targetType = new TypeDescriptor(getClass().getField("scalarMapTarget"));
  assertTrue(conversionService.canConvert(sourceType, targetType));
  try {
    conversionService.convert(map, sourceType, targetType);
  }
  catch (ConversionFailedException ex) {
    assertTrue(ex.getCause() instanceof ConverterNotFoundException);
  }
  conversionService.addConverterFactory(new StringToNumberConverterFactory());
  assertTrue(conversionService.canConvert(sourceType, targetType));
  @SuppressWarnings("unchecked")
  Map<Integer, Integer> result = (Map<Integer, Integer>) conversionService.convert(map, sourceType, targetType);
  assertFalse(map.equals(result));
  assertEquals((Integer) 9, result.get(1));
  assertEquals((Integer) 37, result.get(2));
}
origin: cn.bestwu.simpleframework/simpleframework-core

} else if (e instanceof ConversionFailedException) {
 httpStatusCode = HttpStatus.UNPROCESSABLE_ENTITY.value();
 message = getText(webRequest, "typeMismatch", ((ConversionFailedException) e).getValue(),
   ((ConversionFailedException) e).getTargetType());
 if (!StringUtils.hasText(message)) {
  message = "data.valid.failed";
origin: org.molgenis/molgenis-data-rest

@ExceptionHandler(ConversionFailedException.class)
@ResponseStatus(BAD_REQUEST)
@ResponseBody
public ErrorMessageResponse handleConversionFailedException(ConversionFailedException e) {
 LOG.info("ConversionFailedException occurred", e);
 return new ErrorMessageResponse(new ErrorMessage(e.getMessage()));
}
origin: org.springframework.boot/spring-boot

private Collection<String> findValidValues(BindException ex) {
  ConversionFailedException conversionFailure = findCause(ex,
      ConversionFailedException.class);
  if (conversionFailure != null) {
    Object[] enumConstants = conversionFailure.getTargetType().getType()
        .getEnumConstants();
    if (enumConstants != null) {
      return Stream.of(enumConstants).map(Object::toString)
          .collect(Collectors.toCollection(TreeSet::new));
    }
  }
  return Collections.emptySet();
}
origin: spring-projects/spring-framework

@Test
public void scalarList() throws Exception {
  List<String> list = new ArrayList<>();
  list.add("9");
  list.add("37");
  TypeDescriptor sourceType = TypeDescriptor.forObject(list);
  TypeDescriptor targetType = new TypeDescriptor(getClass().getField("scalarListTarget"));
  assertTrue(conversionService.canConvert(sourceType, targetType));
  try {
    conversionService.convert(list, sourceType, targetType);
  }
  catch (ConversionFailedException ex) {
    assertTrue(ex.getCause() instanceof ConverterNotFoundException);
  }
  conversionService.addConverterFactory(new StringToNumberConverterFactory());
  assertTrue(conversionService.canConvert(sourceType, targetType));
  @SuppressWarnings("unchecked")
  List<Integer> result = (List<Integer>) conversionService.convert(list, sourceType, targetType);
  assertFalse(list.equals(result));
  assertEquals(9, result.get(0).intValue());
  assertEquals(37, result.get(1).intValue());
}
origin: cn.bestwu.simpleframework/simpleframework-web

httpStatusCode = HttpStatus.UNPROCESSABLE_ENTITY.value();
message = getText(webRequest, "typeMismatch",
  ((ConversionFailedException) error).getValue(),
  ((ConversionFailedException) error).getTargetType());
if (!StringUtils.hasText(message)) {
 message = "data.valid.failed";
origin: org.apereo.cas/cas-server-core-util-api

  private String convertValueToDurationIfPossible(final String value) {
    try {
      val service = applicationContext.getEnvironment().getConversionService();
      val dur = service.convert(value, Duration.class);
      if (dur != null) {
        return String.valueOf(dur.toMillis());
      }
    } catch (final ConversionFailedException e) {
      LOGGER.trace(e.getMessage());
    }
    return null;
  }
}
origin: spring-projects/spring-framework

@Nullable
public static Object invokeConverter(GenericConverter converter, @Nullable Object source,
    TypeDescriptor sourceType, TypeDescriptor targetType) {
  try {
    return converter.convert(source, sourceType, targetType);
  }
  catch (ConversionFailedException ex) {
    throw ex;
  }
  catch (Throwable ex) {
    throw new ConversionFailedException(sourceType, targetType, source, ex);
  }
}
origin: spring-projects/spring-framework

@Test
public void collectionMap() throws Exception {
  Map<String, List<String>> map = new HashMap<>();
  map.put("1", Arrays.asList("9", "12"));
  map.put("2", Arrays.asList("37", "23"));
  TypeDescriptor sourceType = TypeDescriptor.forObject(map);
  TypeDescriptor targetType = new TypeDescriptor(getClass().getField("collectionMapTarget"));
  assertTrue(conversionService.canConvert(sourceType, targetType));
  try {
    conversionService.convert(map, sourceType, targetType);
  }
  catch (ConversionFailedException ex) {
    assertTrue(ex.getCause() instanceof ConverterNotFoundException);
  }
  conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
  conversionService.addConverterFactory(new StringToNumberConverterFactory());
  assertTrue(conversionService.canConvert(sourceType, targetType));
  @SuppressWarnings("unchecked")
  Map<Integer, List<Integer>> result = (Map<Integer, List<Integer>>) conversionService.convert(map, sourceType, targetType);
  assertFalse(map.equals(result));
  assertEquals(Arrays.asList(9, 12), result.get(1));
  assertEquals(Arrays.asList(37, 23), result.get(2));
}
origin: spring-projects/spring-data-mongodb

  public URL convert(String source) {
    try {
      return source == null ? null : new URL(source);
    } catch (MalformedURLException e) {
      throw new ConversionFailedException(SOURCE, TARGET, source, e);
    }
  }
}
origin: spring-projects/spring-framework

@Test
public void scalarMap() throws Exception {
  Map<String, String> map = new HashMap<>();
  map.put("1", "9");
  map.put("2", "37");
  TypeDescriptor sourceType = TypeDescriptor.forObject(map);
  TypeDescriptor targetType = new TypeDescriptor(getClass().getField("scalarMapTarget"));
  assertTrue(conversionService.canConvert(sourceType, targetType));
  try {
    conversionService.convert(map, sourceType, targetType);
  }
  catch (ConversionFailedException ex) {
    assertTrue(ex.getCause() instanceof ConverterNotFoundException);
  }
  conversionService.addConverterFactory(new StringToNumberConverterFactory());
  assertTrue(conversionService.canConvert(sourceType, targetType));
  @SuppressWarnings("unchecked")
  Map<Integer, Integer> result = (Map<Integer, Integer>) conversionService.convert(map, sourceType, targetType);
  assertFalse(map.equals(result));
  assertEquals((Integer) 9, result.get(1));
  assertEquals((Integer) 37, result.get(2));
}
origin: org.springframework/spring-core

private void assertNotPrimitiveTargetType(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (targetType.isPrimitive()) {
    throw new ConversionFailedException(sourceType, targetType, null,
        new IllegalArgumentException("A null value cannot be assigned to a primitive type"));
  }
}
origin: spring-projects/spring-framework

@Test
public void testDefaultFormattersOff() throws Exception {
  FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
  factory.setRegisterDefaultFormatters(false);
  factory.afterPropertiesSet();
  FormattingConversionService fcs = factory.getObject();
  TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern"));
  try {
    fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
    fail("This format should not be parseable");
  }
  catch (ConversionFailedException ex) {
    assertTrue(ex.getCause() instanceof NumberFormatException);
  }
}
origin: spring-projects/spring-framework

  @Override
  public Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) {
    throw new ConversionFailedException(sourceType, targetType, source, null);
  }
});
origin: org.apache.camel/camel-spring-boot

if (e.getCause() instanceof ConverterNotFoundException && isArrayOrCollection(value)) {
  return null;
} else {
origin: org.springframework/spring-core

@Nullable
public static Object invokeConverter(GenericConverter converter, @Nullable Object source,
    TypeDescriptor sourceType, TypeDescriptor targetType) {
  try {
    return converter.convert(source, sourceType, targetType);
  }
  catch (ConversionFailedException ex) {
    throw ex;
  }
  catch (Throwable ex) {
    throw new ConversionFailedException(sourceType, targetType, source, ex);
  }
}
origin: spring-projects/spring-framework

throw new ConversionFailedException(sourceType, targetType, source, ex.getTargetException());
throw new ConversionFailedException(sourceType, targetType, source, ex);
org.springframework.core.convertConversionFailedException

Javadoc

Exception to be thrown when an actual type conversion attempt fails.

Most used methods

  • <init>
    Create a new conversion exception.
  • getCause
  • getMessage
  • getTargetType
    Return the target type we tried to convert the value to.
  • getValue
    Return the offending value.
  • getSourceType
    Return the source type we tried to convert the value from.

Popular in Java

  • Finding current android device location
  • requestLocationUpdates (LocationManager)
  • runOnUiThread (Activity)
  • getApplicationContext (Context)
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • JComboBox (javax.swing)
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now