Spring Framework DefaultConversionService - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework DefaultConversionService class.

This code example shows how to use the following methods:
	private MethodParameter paramNotAnnotated;
 
 
	@Before 
	public void setup() throws Exception {
		this.resolver = new DestinationVariableMethodArgumentResolver(new DefaultConversionService());
 
		Method method = getClass().getDeclaredMethod("handleMessage", String.class, String.class, String.class);
		this.paramAnnotated = new MethodParameter(method, 0);
		this.paramAnnotatedValue = new MethodParameter(method, 1);
		this.paramNotAnnotated = new MethodParameter(method, 2);
 
		this.paramAnnotated.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
		GenericTypeResolver.resolveParameterType(this.paramAnnotated, DestinationVariableMethodArgumentResolver.class);
		this.paramAnnotatedValue.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
		GenericTypeResolver.resolveParameterType(this.paramAnnotatedValue, DestinationVariableMethodArgumentResolver.class);
	} 
 
	@Test
	public void supportsParameter() { 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:convert
 
@Test
public class ConvertTest { 
 
  public void testSpring() { 
    DefaultConversionService conversion = new DefaultConversionService();
    Assert.assertEquals(conversion.convert("4.5", Number.class), new BigDecimal("4.5"));
     
    Assert.assertEquals((boolean)conversion.convert("true", boolean.class), true);
  } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
public class GenericMessageConverterTests { 
 
	@Rule 
	public final ExpectedException thrown = ExpectedException.none(); 
 
	private final ConversionService conversionService = new DefaultConversionService(); 
	private final GenericMessageConverter converter = new GenericMessageConverter(conversionService); 
 
	@Test 
	public void fromMessageWithConversion() { 
		Message<String> content = MessageBuilder.withPayload("33").build(); 
		assertEquals(33, converter.fromMessage(content, Integer.class)); 
	} 
 
	@Test 
	public void fromMessageNoConverter() { 
		Message<Integer> content = MessageBuilder.withPayload(1234).build(); 
		assertNull("No converter from integer to locale", converter.fromMessage(content, Locale.class)); 
	} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	private ServletServerHttpResponse response; 
 
 
	@Before 
	public void setUp() { 
		ConversionService conversionService = new DefaultConversionService(); 
		this.converter = new ObjectToStringHttpMessageConverter(conversionService); 
 
		this.servletResponse = new MockHttpServletResponse(); 
		this.response = new ServletServerHttpResponse(this.servletResponse); 
	} 
 
	@Test 
	public void canRead() { 
		assertFalse(this.converter.canRead(Math.class, null)); 
		assertFalse(this.converter.canRead(Resource.class, null)); 
 
		assertTrue(this.converter.canRead(Locale.class, null)); 
		assertTrue(this.converter.canRead(BigInteger.class, null)); 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
	/** 
	 * Create a new instance with a default {@link ConversionService}. 
	 */ 
	public GenericMessageConverter() { 
		this.conversionService = new DefaultConversionService();
	} 
 
	/** 
	 * Create a new instance with the given {@link ConversionService}. 
	 */ 
	public GenericMessageConverter(ConversionService conversionService) {
		Assert.notNull(conversionService, "ConversionService must not be null");
		this.conversionService = conversionService;
	} 
 
 
	@Override 
	public Object fromMessage(Message<?> message, Class<?> targetClass) {
		Object payload = message.getPayload();
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	 * <p>Creates a simple {@link GenericConversionService} instance by default. 
	 * Subclasses may override to customize the ConversionService instance that 
	 * gets created. 
	 */ 
	protected GenericConversionService createConversionService() {
		return new DefaultConversionService();
	} 
 
 
	// implementing FactoryBean 
 
	@Override 
	public ConversionService getObject() {
		return this.conversionService;
	} 
 
	@Override 
	public Class<? extends ConversionService> getObjectType() {
		return GenericConversionService.class;
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	DefaultConversionService conversionService;
 
	@Before 
	public void setUp() { 
 
		this.conversionService = new DefaultConversionService();
		QueryExecutionConverters.registerConvertersIn(conversionService);
	} 
 
	/** 
	 * @see DATACMNS-483 
	 */ 
	@Test
	@SuppressWarnings("unchecked") 
	public void turnsNullIntoGuavaOptional() { 
 
		Optional<Object> optional = conversionService.convert(new NullableWrapper(null), Optional.class);
		assertThat(optional, is(Optional.<Object> absent()));
	} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		this.testBeanModelAttr = new MethodParameter(method, 0); 
		this.testBeanWithoutStringConstructorModelAttr = new MethodParameter(method, 1); 
		this.testBeanWithOptionalModelAttr = new MethodParameter(method, 2); 
 
		ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); 
		initializer.setConversionService(new DefaultConversionService()); 
 
		this.binderFactory = new ServletRequestDataBinderFactory(null, initializer); 
		this.mavContainer = new ModelAndViewContainer(); 
 
		this.request = new MockHttpServletRequest(); 
		this.webRequest = new ServletWebRequest(request); 
	} 
 
 
	@Test 
	public void createAttributeUriTemplateVar() throws Exception { 
		Map<String, String> uriTemplateVars = new HashMap<String, String>(); 
		uriTemplateVars.put("testBean1", "Patty"); 
		this.request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	 * @param beanFactory a bean factory to use for resolving {@code ${...}} placeholder 
	 * and {@code #{...}} SpEL expressions in default values, or {@code null} if default 
	 * values are not expected to contain expressions 
	 */ 
	protected AbstractNamedValueMethodArgumentResolver(ConversionService cs, ConfigurableBeanFactory beanFactory) {
		this.conversionService = (cs != null ? cs : new DefaultConversionService());
		this.configurableBeanFactory = beanFactory;
		this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, null) : null);
	} 
 
 
	@Override 
	public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
		Class<?> paramType = parameter.getParameterType();
		NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
 
		Object arg = resolveArgumentInternal(parameter, message, namedValueInfo.name);
		if (arg == null) {
			if (namedValueInfo.defaultValue != null) {
				arg = resolveDefaultValue(namedValueInfo.defaultValue);
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 * 
 */ 
public class DefaultDatatypeChannelMessageConverter implements MessageConverter, 
		BeanFactoryAware {
 
	private volatile ConversionService conversionService = new DefaultConversionService();
 
	private volatile boolean conversionServiceSet;
 
	/** 
	 * Specify the {@link ConversionService} to use when trying to convert to 
	 * requested type. If this property is not set explicitly but 
	 * the converter is managed within a context, it will attempt to locate a 
	 * bean named "integrationConversionService" defined within that context. 
	 * 
	 * @param conversionService The conversion service. 
	 */ 
	public void setConversionService(ConversionService conversionService) {
		Assert.notNull(conversionService, "'conversionService' must not be null");
		this.conversionService = conversionService;
5
CodeRank
Experience pair programming with AI  Get Codota for Java