I have created a sample project with spring-boot-starter-jersey
.
Sample Code :
Service class
@Service
@Path("/sample")
public class SampleService {
@Autowired
private ConversionService conversionService;
@GET
@Path("/get")
public void get() {
Person p = new Person();
p.setFirstName("A");
p.setLastName("B");
System.out.println(conversionService.convert(p, String.class));
}
}
Sample Converter -
@Component
public class PersonToNameConverter implements Converter<Person, String> {
@Override
public String convert(Person source) {
return source.getFirstName() + " " + source.getLastName();
}
}
Now, spring-boot-starter-jersey
is not providing me the GenericConversionService
bean automatically and also not picking up the custom converters present.
Now, I need to create a GenericConversionService
bean manually to make my job possible.
``` @Bean public ConversionService conversionService() { ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean(); Set<Converter<?, ?>> converterSet = new HashSet<>(); converter.add(new PersonToNameConverter()); factory.setConverters(converterSet); factory.afterPropertiesSet(); return factory.getObject(); }
```
This is fine when I have less custom converter classes. But if I have too many custom converters, then it will gradually increase the code for that bean and I don't want this behaviour to happen.
Is this a bug or was not added for some reason ? If it was not added, then what should be the possible way to solve this issue ?
Comment From: wilkinsona
Please don’t cross-post to the issue tracker and Stack Overflow. At least one person is already trying to help you over there and asking here as well will just duplicate effort and waste people’s time.
Comment From: anishb266
@wilkinsona It didn't solve my issue. That's why this post is here. Can you provide the solution on stackoverflow ?