From 6fb4de675246464ca02c460bb2a141b397084e9d Mon Sep 17 00:00:00 2001 From: Nico Schmitz Date: Tue, 16 Oct 2018 01:49:11 +0200 Subject: [PATCH] Bugfix json serialization --- .../plugins/general/automation/triggers/Trigger.java | 4 ++-- .../plugins/general/automation/triggers/TriggerBg.java | 2 +- .../plugins/general/automation/triggers/TriggerTime.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java index 64f1b0d9fd..2a055b24d6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java @@ -100,9 +100,9 @@ public abstract class Trigger { static Trigger instantiate(JSONObject object) { try { String type = object.getString("type"); - String data = object.getString("data"); + JSONObject data = object.getJSONObject("data"); Class clazz = Class.forName(type); - return ((Trigger) clazz.newInstance()).fromJSON(data); + return ((Trigger) clazz.newInstance()).fromJSON(data.toString()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java index fbad5deea1..3e2abd61a3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java @@ -66,7 +66,7 @@ public class TriggerBg extends Trigger { data.put("threshold", threshold); data.put("comparator", comparator.toString()); data.put("units", units); - o.put("data", data.toString()); + o.put("data", data); } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java index 1abb0362c8..b4aa3d711b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java @@ -156,7 +156,7 @@ public class TriggerTime extends Trigger { data.put("minute", minute); data.put("validTo", validTo); object.put("type", TriggerTime.class.getName()); - object.put("data", data.toString()); + object.put("data", data); } catch (JSONException e) { e.printStackTrace(); }