commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miguel Fernández Martínez <>
Subject [beanutils] Problem registering XMLGregorianCalendar converter
Date Tue, 21 Jan 2014 16:07:45 GMT

I’m trying to register a custom converter for XMLGregorianCalendars to do
the conversión from POJO received by WS (with XMLGregorianCalendar fields)
to my model (Date objects).

I tried to register to process properties with XMLGregorianCalendar.class,
but the it seems to be an anonymous class and in executing time is detected
as XMLGregorianCalendarImpl.class, which doesn’t cause the triggering of my
custom converter.

How can I do this conversion? I can register to
XMLGregorianCalendarImpl.class because it is not a “visible” class…

Here it's my code:


ConvertUtils.register(new XMLGregorianCalendarConverter(),

BeanUtils.copyProperties(result, original);

[…] //”result” is a object from my model with Date properties and
“original” a pojo with properties with the same name but with


*import* javax.xml.datatype.XMLGregorianCalendar;

*import* org.apache.commons.beanutils.converters.DateConverter;

*public* *class* XMLGregorianCalendarConverter

       *private* DateConverter dateConverter =



       *public* <T> T convert(Class<T> type, Object value) {

             *if*(value == *null* || value.toString().length() < 1)

                    *return* *null*;


                    XMLGregorianCalendar xmldate = (XMLGregorianCalendar)

                    *return* (T) xmldate.toGregorianCalendar().getTime();


                    *return* dateConverter.convert(type, value);




Thank you very much for your attention.



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message