@Override public void read(JSONObject object) throws JSONException { setClassName(object.optString(CLASS_NAME, null)); setMethodName(object.optString(METHOD_NAME, null)); setLineNumber(JSONUtils.readInteger(object, LINE_NUMBER)); setFileName(object.optString(FILE_NAME, null)); }
@Override public void read(JSONObject object) throws JSONException { super.read(object); setId(UUID.fromString(object.getString(ID))); setProcessId(JSONUtils.readInteger(object, PROCESS_ID)); setProcessName(object.optString(PROCESS_NAME, null)); setParentProcessId(JSONUtils.readInteger(object, PARENT_PROCESS_ID)); setParentProcessName(object.optString(PARENT_PROCESS_NAME, null)); setErrorThreadId(JSONUtils.readLong(object, ERROR_THREAD_ID)); setErrorThreadName(object.optString(ERROR_THREAD_NAME, null)); setFatal(JSONUtils.readBoolean(object, FATAL)); setAppLaunchTimestamp(JSONDateUtils.toDate(object.getString(APP_LAUNCH_TIMESTAMP))); setArchitecture(object.optString(ARCHITECTURE, null)); }
@Override public void read(JSONObject object) throws JSONException { super.read(object); setSdkName(object.getString(SDK_NAME)); setSdkVersion(object.getString(SDK_VERSION)); setModel(object.getString(MODEL)); setOemName(object.getString(OEM_NAME)); setOsName(object.getString(OS_NAME)); setOsVersion(object.getString(OS_VERSION)); setOsBuild(object.optString(OS_BUILD, null)); setOsApiLevel(JSONUtils.readInteger(object, OS_API_LEVEL)); setLocale(object.getString(LOCALE)); setTimeZoneOffset(object.getInt(TIME_ZONE_OFFSET)); setScreenSize(object.getString(SCREEN_SIZE)); setAppVersion(object.getString(APP_VERSION)); setCarrierName(object.optString(CARRIER_NAME, null)); setCarrierCountry(object.optString(CARRIER_COUNTRY, null)); setAppBuild(object.getString(APP_BUILD)); setAppNamespace(object.optString(APP_NAMESPACE, null)); }
@Test public void readKeyNotExists() throws JSONException { /* Create an empty JSON object. */ JSONObject object = new JSONObject("{}"); /* Verify. */ assertNull(JSONUtils.readInteger(object, "key")); assertNull(JSONUtils.readLong(object, "key")); assertNull(JSONUtils.readBoolean(object, "key")); assertNull(JSONUtils.readMap(object, "key")); assertNull(JSONUtils.readArray(object, "key", new MockLogFactory())); }
@Test public void writeReadObject() throws JSONException { /* Write to JSON object. */ JSONStringer writer = new JSONStringer(); writer.object(); JSONUtils.write(writer, "int", 1); JSONUtils.write(writer, "long", 1000000000L); JSONUtils.write(writer, "boolean", true); writer.endObject(); /* Convert to string. */ String json = writer.toString(); assertNotNull(json); /* Read a JSON object and verify. */ JSONObject object = new JSONObject(json); assertEquals(Integer.valueOf(1), JSONUtils.readInteger(object, "int")); assertEquals(Long.valueOf(1000000000L), JSONUtils.readLong(object, "long")); assertEquals(true, JSONUtils.readBoolean(object, "boolean")); }