From 9bd801bfc6a10e5298cdec6e48ca0506ecdfde53 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 14 May 2020 15:34:34 +0200 Subject: [PATCH] JsonIO: fix longs --- data/JsonIO.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/data/JsonIO.java b/data/JsonIO.java index beff342b..524f99a7 100644 --- a/data/JsonIO.java +++ b/data/JsonIO.java @@ -287,9 +287,14 @@ public class JsonIO { static long getLong(JSONObject json, String key, long def) { if (json.has(key)) { Object o = json.get(key); - if (o instanceof Long) { + if (o instanceof Byte) + return (Byte) o; + if (o instanceof Short) + return (Short) o; + if (o instanceof Integer) + return (Integer) o; + if (o instanceof Long) return (Long) o; - } } return def; @@ -309,8 +314,17 @@ public class JsonIO { static int getInt(JSONObject json, String key, int def) { if (json.has(key)) { Object o = json.get(key); - if (o instanceof Integer) { + if (o instanceof Byte) + return (Byte) o; + if (o instanceof Short) + return (Short) o; + if (o instanceof Integer) return (Integer) o; + if (o instanceof Long) { + try { + return (int) (long) ((Long) o); + } catch (Exception e) { + } } } -- 2.27.0