spring-ldap icon indicating copy to clipboard operation
spring-ldap copied to clipboard

Support conversion of Generalized Date as String to ZonedDateTime

Open kwin opened this issue 9 years ago • 1 comments
trafficstars

Even with ODM there is no built-in conversion from the String representation of date values from LDAP to native Date types (see #167). Please support a conversion from String to ZonedDateTime by default when leveraging ODM.

An example source code for the conversion can be found in https://github.com/vt-middleware/ldaptive/blob/master/beans/src/main/java/org/ldaptive/beans/spring/convert/StringToZonedDateTimeConverter.java.

Currently it is particularly hard to register custom converters with ODM as you have to do something like this

        DefaultObjectDirectoryMapper objectDirectoryMapper = (DefaultObjectDirectoryMapper) ldapTemplate.getObjectDirectoryMapper();
        DefaultConversionService conversionService = new DefaultConversionService();
        conversionService.addConverter(new StringToZonedDateTimeConverter());
        conversionService.addConverter(new ZonedDateTimeToStringConverter());
        conversionService.addConverter(new ConversionServiceConverterManager.StringToNameConverter()); // default converter from string to name
        ConversionServiceConverterManager converterManager = new ConversionServiceConverterManager(conversionService);
        objectDirectoryMapper.setConverterManager(converterManager);

You even to register the built-in string to name converts as the constructor ConversionServiceConverterManager(GenericConversionService conversionService) does not automatically register those. Maybe at the same time providing a simple way of registering new/custom converters could be simplified.

kwin avatar Oct 12 '16 14:10 kwin