4

I've written a custom deserializer for an entity in Spring Boot application. Now I need to access URL parameters and path variables in my custom deserializer for some data manipulation. Please tell me how can i do that.

Thanks

Manisha
  • 775
  • 6
  • 13
  • 30

2 Answers2

1

For path variables deserialization you don't need to involve jackson but you have to "tune" Spring MVC itself by means of defining your own org.springframework.core.convert.converter.Converter

For example:

@Component
public class StringToLocalDateTimeConverter
  implements Converter<String, LocalDateTime> {

    @Override
    public LocalDateTime convert(String source) {
        return LocalDateTime.parse(
          source, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
    }
}

@GetMapping("/findbydate/{date}")
public GenericEntity findByDate(@PathVariable("date") LocalDateTime date) {
    return ...;
}

Here is an article about it.

MarkHuntDev
  • 181
  • 3
  • 21
0

1. HandlerMethodArgumentResolver

See spring-mvc-custom-data-binder, Another answer

2. HandlerInterceptor

See Interception

cuz
  • 1,172
  • 11
  • 12