jeudi 20 août 2020

Spring MethodArgumentTypeMismatchException with Optional

I'm doing some error handling for MethodArgumentTypeMismatchException in Spring.

I know (human wise I mean) the type is Optional<LocalDate>. e.getRequiredType() gives me just the Optional.class. I'm able to get at the T type through e.getParameter().getGenericParameterType() (or the one place I've found it so far). Through that, I get a ParameterTypeImpl which returns java.util.Optional<java.time.LocalDate>. ParameterTypeImpl is private and doesn't expose a way to get at "actualTypeArgument" to get the LocalDate type.

Is there another way to get LocalDate from the exception? I know I can get at the private members through reflection, but I'd probably just parse the name between the <> before going to reflection.





Aucun commentaire:

Enregistrer un commentaire