Results 1 to 4 of 4

Thread: Register TypeConverter/PropertyEditor w/Spring Batch?

  1. #1
    Join Date
    Jul 2005
    Location
    Austin, TX
    Posts
    137

    Default Register TypeConverter/PropertyEditor w/Spring Batch?

    Hi all,

    Probably a dumb question.

    I have an ItemProcessor implementation that I'm using in a step, and one of its properties is of type java.util.Date. I know in Spring 3, registering custom type converters changed a bit, so I'm not sure how to register a TypeConverter<String,Date> so that when Spring Batch instantiates my ItemProcessor bean, it converts the SpEL expression in the config,
    Code:
    ...
    <constructor-arg value="#{jobParameters['date']}" />
    ...
    into a proper java.util.Date using a particular format ("yyyyMMdd").

    How should I do this? What's the Spring-supplied TypeConverter<String,Date> that takes a format string, if there is one?

    RTFMs welcome, but I already looked at Spring 3's reference guide 5.5 "Spring 3 Type Conversion" and am not really sure where to set a ConversionService in Spring Batch or if & how I'm supposed to be using an org.springframework.beans.propertyeditors.CustomDa teEditor.

    Thanks,
    Matthew

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    SpEL expressions are converted by the BeanFactory when the bean is instantiated, so you should be fine if you just register the Converter (not TypeConverter) or PropertyEditor (legacy code but it still works) with the BeanFactory, i.e. nothing to do with Spring Batch. Converters are registered by declaring a ConversionService bean (e.g. using ConversionServiceFactoryBean) and PropertyEditors are registered by declaring a CustomPropertyEditor.

    If the Spring user guide isn't clear on this I would raise a JIRA with SPR-*.

  3. #3
    Join Date
    Jul 2005
    Location
    Austin, TX
    Posts
    137

    Default

    Quote Originally Posted by Dave Syer View Post
    ...Converters are registered by declaring a ConversionService bean (e.g. using ConversionServiceFactoryBean) and PropertyEditors are registered by declaring a CustomPropertyEditor.
    Is there an XML namespace for that yet?

    I guess I was surprised to see that there is no implementation out of the box of Converter<String,java.util.Date>, Converter<String,org.joda.time.DateTime>, etc.

  4. #4
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    There's no namespace, and there isn't much call for date conversion outside webapps, so the converter features have all gone into the Formatter hierarchy in Spring 3.0, which is more to do with binding and rendering than it is to do with pure conversion. There *is* support there for Joda time, but still no simple StringToDateConverter.

    I argued quite strongly for a StringToDateConverter in Spring 3.0, but we couldn't agree on how to specify the format. Go figure. open a JIRA against SPR-* if you feel strongly. Note that the CustomDateEditor is still there and it still works.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •