ConverterNotFound Using Spring Roo

Using Roo has been really awesome! I would recommend it to anyone starting a web project for the first time that really wanted to use Spring and Java.

Just ran into this error tonight and thought I would blog a little bit about it in case others run into the same error… *plus* I wanted to show a bit of this new Google Guava project!

1
2
3
4
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from 'java.util.Se
t'
to 'java.lang.String'
        at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:181)
        at org.springframework.expression.spel.support.StandardTypeConverter.convertValue(StandardTypeConverter.java:66)

This meant that we need a converter for the show view since the default create from Roo does not take care of the ONE_TO_MANY relationship. Below is the code that was needed in my case.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * A central place to register application Converters and Formatters.
 */

@RooConversionService
public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {

    Converter<Set<Property>, String> getPropertySetConverter() {
        return new Converter<Set<Property>, String>() {
            public String convert(Set<Property> properties) {
                return Joiner.on(",").join(properties.toArray());      // 1
            }
        };
    }
  @Override
  protected void installFormatters(FormatterRegistry registry) {
    super.installFormatters(registry);
    registry.addConverter(getPropertySetConverter());
  }
 
}

Notice the line:

1
return Joiner.on(",").join(properties.toArray());      // 1

This is using the Google Guava project to create a String instead of using the old school StringBuilder approach.

5 thoughts on “ConverterNotFound Using Spring Roo

  1. How timely (blog entry coincides on day which I encounter problem).

    Just my issue exactly thanx (also to google for indexing you this timely and for providing Guava — yet another thing to look into).

    I don’t know if you know EMF, but the links on http://blog.efef.dk/?p=241 regarding EMF2Roo actually can be made to work if you just follow steps carefully (as usual). I am just getting things set up again after around a year outside java development.

    Cheers,
    /)/3

  2. Funny thing, I’ve also encountered this with Roo; however, only when using the generated show.jspx from a custom Web Flow. It looks like Roo does handle the Set to String conversion via a default ApplicationConversionService (should be in same package as your entities) – I didn’t have to generate my own, my Show Entity pages with OneToMany relationships just work.

    This only works via Spring MVC (not WebFlow) though. The fix (for WebFlow) would seem to be to use the same conversion service when configuring the FlowBuilderServices object – but alas, it accepts a different ConversionService interface type (the one from Spring Binding rather than Core).

  3. This solution really works, thanks, in my case I changed a domain object like the following one, thanks for the solution;

    @RooConversionService
    public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {

    Converter getPropertySetConverter() {
    return new Converter() {
    public String convert(ProductType properties) {
    return properties.getType().toString(); // 1
    }
    };
    }
    @Override
    protected void installFormatters(FormatterRegistry registry) {
    super.installFormatters(registry);
    registry.addConverter(getPropertySetConverter());
    }

    }

Comments are closed.