Example usage for org.springframework.core.convert.support GenericConversionService canConvert

List of usage examples for org.springframework.core.convert.support GenericConversionService canConvert

Introduction

In this page you can find the example usage for org.springframework.core.convert.support GenericConversionService canConvert.

Prototype

@Override
    public boolean canConvert(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) 

Source Link

Usage

From source file:org.ldaptive.beans.spring.SpringLdapEntryMapper.java

/**
 * Adds default converters to the supplied conversion service.
 *
 * @param  service  to add default converters to
 *//*from   w w  w  . j  a  va2 s. c  o  m*/
protected void addDefaultConverters(final GenericConversionService service) {
    if (!service.canConvert(String.class, Calendar.class)) {
        service.addConverter(new Converter<String, Calendar>() {
            @Override
            public Calendar convert(final String s) {
                final GeneralizedTimeValueTranscoder transcoder = new GeneralizedTimeValueTranscoder();
                return transcoder.decodeStringValue(s);
            }
        });
    }
    if (!service.canConvert(Calendar.class, String.class)) {
        service.addConverter(new Converter<Calendar, String>() {
            @Override
            public String convert(final Calendar c) {
                final GeneralizedTimeValueTranscoder transcoder = new GeneralizedTimeValueTranscoder();
                return transcoder.encodeStringValue(c);
            }
        });
    }
}

From source file:org.fenixedu.bennu.spring.FenixEDUBaseController.java

@InitBinder
public void initBinder(final WebDataBinder binder) {
    GenericConversionService conversionService = (GenericConversionService) binder.getConversionService();
    if (!conversionService.canConvert(String.class, IBean.class)) {
        GsonBuilder builder = new GsonBuilder();
        registerTypeAdapters(builder);//ww w  .  j  av a 2 s. c om
        conversionService.addConverter(new BeanConverterService(builder));
    }
    conversionService.addConverter(new CountryConverterService());
    conversionService.addConverter(new DistrictConverterService());
    conversionService.addConverter(new MunicipalityConverterService());

}