catch number parse exception in literal creation

This commit is contained in:
Jörg Prante 2018-01-30 00:33:24 +01:00
parent f065ce40bd
commit 6f932191b6
2 changed files with 20 additions and 15 deletions

View file

@ -94,20 +94,25 @@ public class DefaultLiteral implements Literal, Comparable<Literal> {
return value; return value;
} }
String s = value.toString(); String s = value.toString();
switch (type.toString()) { try {
case "xsd:long": switch (type.toString()) {
return Long.parseLong(s); case "xsd:long":
case "xsd:int": return Long.parseLong(s);
case "xsd:gYear": case "xsd:int":
return Integer.parseInt(s); return Integer.parseInt(s);
case "xsd:boolean": case "xsd:gYear":
return Boolean.parseBoolean(s); return Integer.parseInt(s);
case "xsd:float": case "xsd:boolean":
return Float.parseFloat(s); return Boolean.parseBoolean(s);
case "xsd:double": case "xsd:float":
return Double.parseDouble(s); return Float.parseFloat(s);
default: case "xsd:double":
return s; return Double.parseDouble(s);
default:
return s;
}
} catch (NumberFormatException e) {
return null;
} }
} }

View file

@ -1,6 +1,6 @@
group = org.xbib group = org.xbib
name = content name = content
version = 1.2.1 version = 1.2.2
jackson.version = 2.8.11 jackson.version = 2.8.11
xbib-net.version = 1.0.0 xbib-net.version = 1.0.0