Answer the question
In order to leave comments, you need to log in
How to make a different string deserializer for different handles in Spring?
Problem: empty strings ("") arrive in the request, as well as those consisting of only spaces.
Googled, added a simple deserializer to the config:
@Bean(name = JACKSON_MAPPER_BEAN_NAME)
public ObjectMapper objectMapper(StatusNameResolver resolver) {
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule blankStringModule = new SimpleModule();
blankStringModule.addDeserializer(
String.class,
new StdDeserializer<String>(String.class) {
@Override
public String deserialize(JsonParser parser, DeserializationContext context)
throws IOException {
String result = StringDeserializer.instance.deserialize(parser, context);
if (StringUtils.isBlank(result)) {
return null;
}
return result;
}
});
objectMapper.registerModule(blankStringModule);
return objectMapper;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question