Skip to content

Commit 015a3d8

Browse files
committed
Refactor
1 parent cc708e3 commit 015a3d8

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

build.savant

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ logbackVersion = "1.5.13"
2929
slf4jVersion = "2.0.13"
3030
testngVersion = "7.8.0"
3131

32-
project(group: "org.primeframework", name: "prime-mvc", version: "5.7.0", licenses: ["ApacheV2_0"]) {
32+
project(group: "org.primeframework", name: "prime-mvc", version: "5.8.0", licenses: ["ApacheV2_0"]) {
3333
workflow {
3434
fetch {
3535
// Dependency resolution order:

src/main/java/org/primeframework/mvc/content/json/BaseJacksonContentHandler.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
* @author Brian Pontarelli
5656
*/
5757
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+
5861
private static final Logger logger = LoggerFactory.getLogger(BaseJacksonContentHandler.class);
5962

6063
protected final ExpressionEvaluator expressionEvaluator;
@@ -205,17 +208,17 @@ private void addFieldError(InvalidFormatException e) {
205208
if (field.equals("")) {
206209
messageStore.add(new SimpleMessage(MessageType.ERROR, code, messageProvider.getMessage(code, "unknown", "Possible conversion error", e.getMessage())));
207210
} 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);
210211
String messageText = e.getMessage();
211-
Matcher m = stuff.matcher(messageText);
212+
Matcher matchesEnumNotValidValue = invalidEnumerationValue.matcher(messageText);
212213
String message = null;
213-
if (m.matches()) {
214+
if (matchesEnumNotValidValue.matches()) {
214215
code = "[invalid]%s".formatted(field);
216+
// if we have an invalid enum value, provide a better message
215217
message = messageProvider.getMessage(code,
216-
m.group(1),
217-
m.group(2));
218+
matchesEnumNotValidValue.group(1),
219+
matchesEnumNotValidValue.group(2));
218220
}
221+
// otherwise, fall back to what we know
219222
if (message == null) {
220223
message = messageProvider.getMessage(code, field, "Possible conversion error", messageText);
221224
}

0 commit comments

Comments
 (0)