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

How to use
convert
method
in
org.springframework.core.convert.ConversionService

Best Java code snippets using org.springframework.core.convert.ConversionService.convert (Showing top 20 results out of 1,197)

origin: spring-projects/spring-framework

  @Override
  @Nullable
  public T convert(S source) {
    return this.conversionService.convert(source, this.targetType);
  }
}
origin: spring-projects/spring-framework

@Nullable
protected String formatUriValue(@Nullable ConversionService cs, @Nullable TypeDescriptor sourceType, Object value) {
  if (value instanceof String) {
    return (String) value;
  }
  else if (cs != null) {
    return (String) cs.convert(value, sourceType, STRING_TYPE_DESCRIPTOR);
  }
  else {
    return value.toString();
  }
}
origin: spring-projects/spring-framework

@Override
protected Long getContentLength(Object obj, @Nullable MediaType contentType) {
  String value = this.conversionService.convert(obj, String.class);
  if (value == null) {
    return 0L;
  }
  return this.stringHttpMessageConverter.getContentLength(value, contentType);
}
origin: spring-projects/spring-framework

@Nullable
private Object convertKey(Object sourceKey, TypeDescriptor sourceType, @Nullable TypeDescriptor targetType) {
  if (targetType == null) {
    return sourceKey;
  }
  return this.conversionService.convert(sourceKey, sourceType.getMapKeyTypeDescriptor(sourceKey), targetType);
}
origin: spring-projects/spring-framework

@Nullable
private Object convertValue(Object sourceValue, TypeDescriptor sourceType, @Nullable TypeDescriptor targetType) {
  if (targetType == null) {
    return sourceValue;
  }
  return this.conversionService.convert(sourceValue, sourceType.getMapValueTypeDescriptor(sourceValue), targetType);
}
origin: spring-projects/spring-framework

  @Override
  public Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType) throws EvaluationException {
    return this.service.convert(value, sourceType, targetType);
  }
}
origin: spring-projects/spring-framework

@Nullable
private Object convertFromByteBuffer(ByteBuffer source, TypeDescriptor targetType) {
  byte[] bytes = new byte[source.remaining()];
  source.get(bytes);
  if (targetType.isAssignableTo(BYTE_ARRAY_TYPE)) {
    return bytes;
  }
  return this.conversionService.convert(bytes, BYTE_ARRAY_TYPE, targetType);
}
origin: spring-projects/spring-framework

@Override
protected void writeInternal(Object obj, HttpOutputMessage outputMessage) throws IOException {
  String value = this.conversionService.convert(obj, String.class);
  if (value != null) {
    this.stringHttpMessageConverter.writeInternal(value, outputMessage);
  }
}
origin: spring-projects/spring-framework

private Object convertToByteBuffer(@Nullable Object source, TypeDescriptor sourceType) {
  byte[] bytes = (byte[]) (source instanceof byte[] ? source :
      this.conversionService.convert(source, sourceType, BYTE_ARRAY_TYPE));
  if (bytes == null) {
    return ByteBuffer.wrap(new byte[0]);
  }
  ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
  byteBuffer.put(bytes);
  // Extra cast necessary for compiling on JDK 9 plus running on JDK 8, since
  // otherwise the overridden ByteBuffer-returning rewind method would be chosen
  // which isn't available on JDK 8.
  return ((Buffer) byteBuffer).rewind();
}
origin: spring-projects/spring-framework

@Nullable
private Object convertFromStream(@Nullable Stream<?> source, TypeDescriptor streamType, TypeDescriptor targetType) {
  List<Object> content = (source != null ? source.collect(Collectors.<Object>toList()) : Collections.emptyList());
  TypeDescriptor listType = TypeDescriptor.collection(List.class, streamType.getElementTypeDescriptor());
  return this.conversionService.convert(content, listType, targetType);
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (source == null) {
    return null;
  }
  TypeDescriptor targetElementType = targetType.getElementTypeDescriptor();
  Assert.state(targetElementType != null, "No target element type");
  Object target = Array.newInstance(targetElementType.getType(), 1);
  Object targetElement = this.conversionService.convert(source, sourceType, targetElementType);
  Array.set(target, 0, targetElement);
  return target;
}
origin: spring-projects/spring-framework

private Object convertToStream(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor streamType) {
  TypeDescriptor targetCollection = TypeDescriptor.collection(List.class, streamType.getElementTypeDescriptor());
  List<?> target = (List<?>) this.conversionService.convert(source, sourceType, targetCollection);
  if (target == null) {
    target = Collections.emptyList();
  }
  return target.stream();
}
origin: spring-projects/spring-framework

@Override
@SuppressWarnings("unchecked")
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (!sourceType.isAssignableTo(this.printerObjectType)) {
    source = this.conversionService.convert(source, sourceType, this.printerObjectType);
  }
  if (source == null) {
    return "";
  }
  return this.printer.print(source, LocaleContextHolder.getLocale());
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (source == null) {
    return null;
  }
  Method finder = getFinder(targetType.getType());
  Assert.state(finder != null, "No finder method");
  Object id = this.conversionService.convert(
      source, sourceType, TypeDescriptor.valueOf(finder.getParameterTypes()[0]));
  return ReflectionUtils.invokeMethod(finder, source, id);
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object convertValue(@Nullable Object value, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) {
  try {
    return this.conversionService.convert(value, sourceType, targetType);
  }
  catch (ConversionException ex) {
    throw new SpelEvaluationException(ex, SpelMessage.TYPE_CONVERSION_ERROR,
        (sourceType != null ? sourceType.toString() : (value != null ? value.getClass().getName() : "null")),
        targetType.toString());
  }
}
origin: spring-projects/spring-framework

@Override
@Nullable
public String getAsText() {
  if (this.canConvertToString) {
    return (String) this.conversionService.convert(getValue(), this.targetDescriptor, TypeDescriptor.valueOf(String.class));
  }
  else {
    return null;
  }
}
origin: spring-projects/spring-framework

@Override
public void setAsText(@Nullable String text) throws IllegalArgumentException {
  setValue(this.conversionService.convert(text, TypeDescriptor.valueOf(String.class), this.targetDescriptor));
}
origin: spring-projects/spring-framework

@Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
    throws IOException, HttpMessageNotReadableException {
  String value = this.stringHttpMessageConverter.readInternal(String.class, inputMessage);
  Object result = this.conversionService.convert(value, clazz);
  if (result == null) {
    throw new HttpMessageNotReadableException(
        "Unexpected null conversion result for '" + value + "' to " + clazz,
        inputMessage);
  }
  return result;
}
origin: spring-projects/spring-framework

@Test
public void withConversionService() {
  ConversionService conversionService = new DefaultConversionService();
  assertTrue(conversionService.canConvert(String.class, MimeType.class));
  MimeType mimeType = MimeType.valueOf("application/xml");
  assertEquals(mimeType, conversionService.convert("application/xml", MimeType.class));
}
origin: spring-projects/spring-framework

@Test
public void testWithConversionService() {
  ConversionService conversionService = new DefaultConversionService();
  assertTrue(conversionService.canConvert(String.class, MediaType.class));
  MediaType mediaType = MediaType.parseMediaType("application/xml");
  assertEquals(mediaType, conversionService.convert("application/xml", MediaType.class));
}
org.springframework.core.convertConversionServiceconvert

Javadoc

Convert the source to targetType.

Popular methods of ConversionService

  • canConvert
    Return true if objects of sourceType can be converted to the targetType. The TypeDescriptors provide

Popular in Java

  • Updating database using SQL prepared statement
  • findViewById (Activity)
  • getExternalFilesDir (Context)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Top Vim plugins
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