Skip to content

Commit c323191

Browse files
committed
refactor: get rid of regexp check
Regexp decreases performance, so there is more sense to rely on parse exceptions in that case. Refs: #157
1 parent 594a1fb commit c323191

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/graphql/scalars/datetime/SecondsSinceEpochScalar.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ public Long serialize(Object input, GraphQLContext graphQLContext, Locale locale
6464
return number.longValue();
6565
}
6666
if (input instanceof String) {
67-
String string = (String) input;
68-
if (string.matches("\\d+")) {
69-
return Long.parseLong(string);
67+
try {
68+
return Long.parseLong((String) input);
69+
} catch (NumberFormatException e) {
70+
throw new CoercingSerializeException(
71+
"Invalid seconds since epoch value : '" + input + "'. Expected a string containing only digits.",
72+
e
73+
);
7074
}
71-
throw new CoercingSerializeException(
72-
"Invalid seconds since epoch value : '" + string + "'. Expected a string containing only digits."
73-
);
7475
}
7576
if (input instanceof TemporalAccessor) {
7677
TemporalAccessor temporalAccessor = (TemporalAccessor) input;

0 commit comments

Comments
 (0)