forked from extern/Unexpected-Keyboard
ListGroupPreference.Serializer: Allow exceptions
(De)serializing might raise exceptions, which are handled by dropping the failing item.
This commit is contained in:
parent
0269cd65ea
commit
03f2b8df70
@ -97,7 +97,13 @@ public abstract class ListGroupPreference<E> extends PreferenceGroup
|
|||||||
{
|
{
|
||||||
List<Object> serialized_items = new ArrayList<Object>();
|
List<Object> serialized_items = new ArrayList<Object>();
|
||||||
for (E it : items)
|
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();
|
return (new JSONArray(serialized_items)).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,11 +252,11 @@ public abstract class ListGroupPreference<E> extends PreferenceGroup
|
|||||||
public interface Serializer<E>
|
public interface Serializer<E>
|
||||||
{
|
{
|
||||||
/** [obj] is an object returned by [save_item()]. */
|
/** [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
|
/** Serialize an item into JSON. Might return an object that can be inserted
|
||||||
in a [JSONArray]. */
|
in a [JSONArray]. */
|
||||||
Object save_item(E v);
|
Object save_item(E v) throws JSONException;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StringSerializer implements Serializer<String>
|
public static class StringSerializer implements Serializer<String>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user