Spring Data Rest: custom converter <Entity, Resource> is never called
I am trying to implement custom Converterfor an object Entityfor Resourcewith Spring Data Rest, but the converter is never called.
I follow this documentation :
If your project should have output in a different format, it can be completely replaced by the outgoing JSON default view with your own. If you register your own ConversionService in ApplicationContext and register your own Converter, then you can return the resource of your choice.
What I tried to do.
I have a class @Configurationthat extends RepositoryRestMvcConfigurationusing this method:
@Configuration
@EnableWebMvc
@EnableHypermediaSupport(type = HypermediaType.HAL)
public class RepositoryBaseConfiguration extends RepositoryRestMvcConfiguration {
@Override
public DefaultFormattingConversionService defaultConversionService() {
return super.defaultConversionService();
}
}
, RepositoryRestConfigurerAdapter, :
@Configuration
public class RepositoryBaseConfigurerAdapter extends RepositoryRestConfigurerAdapter {
@Override
public void configureConversionService(ConfigurableConversionService conversionService) {
if(!conversionService.canConvert(Entity.class, Resource.class))
conversionService.addConverter(new EntityConverter());
super.configureConversionService(conversionService);
}
}
, , ...
EntityConverter:
@Component
public class EntityConverter implements Converter<Entity, Resource> {
@Override
public Resource convert(Entity source) {
System.out.println("method convert of class EntityConverter");
return null;
}
}
"convert" Spring Data Rest.
/?
.
0
:
: