@Override public void read(JSONObject object) throws JSONException { if (!object.getString(TYPE).equals(getType())) { throw new JSONException("Invalid type"); } setTimestamp(JSONDateUtils.toDate(object.getString(TIMESTAMP))); if (object.has(SID)) { setSid(UUID.fromString(object.getString(SID))); } setDistributionGroupId(object.optString(DISTRIBUTION_GROUP_ID, null)); setUserId(object.optString(USER_ID, null)); if (object.has(DEVICE)) { Device device = new Device(); device.read(object.getJSONObject(DEVICE)); setDevice(device); } }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, TYPE, getType()); writer.key(TIMESTAMP).value(JSONDateUtils.toString(getTimestamp())); JSONUtils.write(writer, SID, getSid()); JSONUtils.write(writer, DISTRIBUTION_GROUP_ID, getDistributionGroupId()); JSONUtils.write(writer, USER_ID, getUserId()); if (getDevice() != null) { writer.key(DEVICE).object(); getDevice().write(writer); writer.endObject(); } }