Answer the question
In order to leave comments, you need to log in
Why doesn't Spring use Jackson for the parameter in the endpoint?
Good afternoon.
There is a controller, the endpoint in this controller has a requested parameter, which is an Enum, below is an example:
@RequestMapping("/")
public void foo(@RequestParam(value="enum") Enum enum) {
//some logic
}
public enum Enum {
ONE, TWO;
@JsonCreator
public static Enum safeValueOf(String value) {
return Stream.of(Enum.values())
.filter(i -> i.name().equals(value))
.findAny()
.orElse(null);
}
}
Answer the question
In order to leave comments, you need to log in
Why use Jackson for this?
For that matter, it would be much more logical to write an implementation of org.springframework.core.convert.converter.Converter that will cast the string to the desired value.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question