diff options
| author | Jules Aguillon | 2023-08-10 12:49:57 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2023-08-16 12:20:40 +0200 |
| commit | 03f2b8df7031baf5bc95ad1d1530e327c9d3ca7c (patch) | |
| tree | ec4db5f416f8a2aae4f2790d560e59b951189492 /srcs | |
| parent | 0269cd65ea57a5046783bcc88243f8f2407952d8 (diff) | |
| download | unexpected-keyboard-03f2b8df7031baf5bc95ad1d1530e327c9d3ca7c.tar.gz unexpected-keyboard-03f2b8df7031baf5bc95ad1d1530e327c9d3ca7c.zip | |
ListGroupPreference.Serializer: Allow exceptions
(De)serializing might raise exceptions, which are handled by dropping
the failing item.
Diffstat (limited to 'srcs')
| -rw-r--r-- | srcs/juloo.keyboard2/ListGroupPreference.java | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/srcs/juloo.keyboard2/ListGroupPreference.java b/srcs/juloo.keyboard2/ListGroupPreference.java index 9136a0c..e69162c 100644 --- a/srcs/juloo.keyboard2/ListGroupPreference.java +++ b/srcs/juloo.keyboard2/ListGroupPreference.java @@ -97,7 +97,13 @@ public abstract class ListGroupPreference<E> extends PreferenceGroup { List<Object> serialized_items = new ArrayList<Object>(); for (E it : items) - serialized_items.add(serializer.save_item(it)); + { + try + { + serialized_items.add(serializer.save_item(it)); + } + catch (JSONException e) {} + } return (new JSONArray(serialized_items)).toString(); } @@ -246,11 +252,11 @@ public abstract class ListGroupPreference<E> extends PreferenceGroup public interface Serializer<E> { /** [obj] is an object returned by [save_item()]. */ - E load_item(Object obj); + E load_item(Object obj) throws JSONException; /** Serialize an item into JSON. Might return an object that can be inserted in a [JSONArray]. */ - Object save_item(E v); + Object save_item(E v) throws JSONException; } public static class StringSerializer implements Serializer<String> |
