|
55 | 55 | * @author Brian Pontarelli |
56 | 56 | */ |
57 | 57 | public abstract class BaseJacksonContentHandler implements ContentHandler { |
| 58 | + private static final Pattern invalidEnumerationValue = Pattern.compile("Cannot deserialize value of type `\\S+` from \\S+ (\\S+): not one of the values accepted for Enum class: \\[(.*)]$.*", |
| 59 | + Pattern.DOTALL | Pattern.MULTILINE); |
| 60 | + |
58 | 61 | private static final Logger logger = LoggerFactory.getLogger(BaseJacksonContentHandler.class); |
59 | 62 |
|
60 | 63 | protected final ExpressionEvaluator expressionEvaluator; |
@@ -205,17 +208,17 @@ private void addFieldError(InvalidFormatException e) { |
205 | 208 | if (field.equals("")) { |
206 | 209 | messageStore.add(new SimpleMessage(MessageType.ERROR, code, messageProvider.getMessage(code, "unknown", "Possible conversion error", e.getMessage()))); |
207 | 210 | } else { |
208 | | - Pattern stuff = Pattern.compile("Cannot deserialize value of type `\\S+` from \\S+ (\\S+): not one of the values accepted for Enum class: \\[(.*)]$.*", |
209 | | - Pattern.DOTALL | Pattern.MULTILINE); |
210 | 211 | String messageText = e.getMessage(); |
211 | | - Matcher m = stuff.matcher(messageText); |
| 212 | + Matcher matchesEnumNotValidValue = invalidEnumerationValue.matcher(messageText); |
212 | 213 | String message = null; |
213 | | - if (m.matches()) { |
| 214 | + if (matchesEnumNotValidValue.matches()) { |
214 | 215 | code = "[invalid]%s".formatted(field); |
| 216 | + // if we have an invalid enum value, provide a better message |
215 | 217 | message = messageProvider.getMessage(code, |
216 | | - m.group(1), |
217 | | - m.group(2)); |
| 218 | + matchesEnumNotValidValue.group(1), |
| 219 | + matchesEnumNotValidValue.group(2)); |
218 | 220 | } |
| 221 | + // otherwise, fall back to what we know |
219 | 222 | if (message == null) { |
220 | 223 | message = messageProvider.getMessage(code, field, "Possible conversion error", messageText); |
221 | 224 | } |
|
0 commit comments