What you need is Spring's ConversionService
. Here's the reference: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#core-convert
Simply implement Converter
similar to this:
public class StringToPortalBrandingConverter implements Converter<String, PortalBranding> {
@Inject // or @Autowire
SomeService someService; // Some service or other dependency you need.
@Override
public PortalBranding convert(String source) {
// Do your conversion from 'source' to 'PortalBranding' here.
// You can make use of your injected 'someService' as well.
...
return portalBranding;
}
}
Then, you just need to tell Spring about your custom converter:
<mvc:annotation-driven conversion-service="conversionService"/>
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="yourpackage.StringToPortalBrandingConverter"/>
</set>
</property>
</bean>
That's all there is to it.