specification-arg-resolver icon indicating copy to clipboard operation
specification-arg-resolver copied to clipboard

Work with char/Character for filtering

Open abhishekshrivastava-proctur opened this issue 5 years ago • 1 comments

I tried to use this to filter based on char value but couldn't get it to do so. Am I implementing wrong or it doesn't support that?

For me adding the code below worked:

I was missing to pass the conversionService to the new SpecificationArgumentResolver at first, which made it not work. Now it does work fine. MAybe this helps you too @abhishekshrivastava-proctur ?

@Configuration
@EnableScheduling
public class SpecificationConfig implements WebMvcConfigurer {

    @Autowired
    @Qualifier("mvcConversionService")
    ConversionService conversionService;

    @Override
    public void addArgumentResolvers(final List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new SpecificationArgumentResolver(conversionService));
    }

    @Override
    public void addFormatters(final FormatterRegistry registry) {
        registry.addConverter(new StringToCharacterConverter());
    }

    public static class StringToCharacterConverter implements Converter<String, Character> {
        @Override
        public Character convert(final String charString) {
            return charString.charAt(0);
        }
    }

}

H3rby7 avatar Aug 10 '20 14:08 H3rby7

direct support for chars/Characters added in v2.17.0 (released today)

tkaczmarzyk avatar Jan 16 '23 15:01 tkaczmarzyk