Groovy interface impl failing instanceof test in Spring

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Groovy interface impl failing instanceof test in Spring

John Thompson
I'm playing around with the Spring type conversion service (see 6.5 http://static.springsource.org/spring/docs/current/spring-framework-reference/html/validation.html)

I have a converter implemented as:

class BusinessHoursToExtJSEvent implements Converter<BusinessHours, ExtJSEvent>{

    @Override
    ExtJSEvent convert(BusinessHours businessHours) {
        DateTimeFormatter fmt = DateTimeFormat.forPattern("EEE");

        def event = new ExtJSEvent()
        event.id = businessHours.id
        event.cid = businessHours.provider?.id
        event.loc = ''
        event.startDate = businessHours.startDate
        event.endDate = businessHours.endDate
        event.title = "Hours Open for ${fmt.print(businessHours.startDate)}"

        event
    }
}

But its failing the instanceof test in this class from spring:
        public static void registerConverters(Set<?> converters, ConverterRegistry registry) {
                if (converters != null) {
                        for (Object converter : converters) {
                                if (converter instanceof GenericConverter) {
                                        registry.addConverter((GenericConverter) converter);
                                }
                                else if (converter instanceof Converter<?, ?>) {
                                        registry.addConverter((Converter<?, ?>) converter);
                                }
                                else if (converter instanceof ConverterFactory<?, ?>) {
                                        registry.addConverterFactory((ConverterFactory<?, ?>) converter);
                                }
                                else {
                                        throw new IllegalArgumentException("Each converter object must implement one of the " +
                                                        "Converter, ConverterFactory, or GenericConverter interfaces");
                                }
                        }
                }
        }

I'm guessing its because I implemented the class in Groovy.  I can refactor to use a Java implementation.  But posting the question because I'm curious why this is failing & if there is a work around.  (Using Grails 2.0.1 w/Groovy 1.8.6)
JT
jts-blog.com