| 3354 | } |
| 3355 | |
| 3356 | @TypeConverter |
| 3357 | public static Address[] decodeAddresses(String json) { |
| 3358 | if (json == null) |
| 3359 | return null; |
| 3360 | |
| 3361 | List<Address> result = new ArrayList<>(); |
| 3362 | try { |
| 3363 | JSONArray jroot = new JSONArray(json); |
| 3364 | for (int i = 0; i < jroot.length(); i++) { |
| 3365 | Object item = jroot.get(i); |
| 3366 | if (jroot.get(i) instanceof JSONArray) |
| 3367 | for (int j = 0; j < ((JSONArray) item).length(); j++) |
| 3368 | result.add(InternetAddressJson.from((JSONObject) ((JSONArray) item).get(j))); |
| 3369 | else |
| 3370 | result.add(InternetAddressJson.from((JSONObject) item)); |
| 3371 | } |
| 3372 | } catch (JSONException ex) { |
| 3373 | Log.i(ex); |
| 3374 | } catch (Throwable ex) { |
| 3375 | // Compose can store invalid addresses |
| 3376 | Log.w(ex); |
| 3377 | } |
| 3378 | return result.toArray(new Address[0]); |
| 3379 | } |
| 3380 | |
| 3381 | @TypeConverter |
| 3382 | public static EntityLog.Type toLogType(int ordinal) { |