private static void writePropertyValue(JSONStringer writer, Object value) throws JSONException { if (value == null) { JSONUtils.write(writer, PROPERTY_TYPE, PROPERTY_TYPE_CLEAR); } else if (value instanceof Boolean) { JSONUtils.write(writer, PROPERTY_TYPE, PROPERTY_TYPE_BOOLEAN); JSONUtils.write(writer, PROPERTY_VALUE, value); } else if (value instanceof Number) { JSONUtils.write(writer, PROPERTY_TYPE, PROPERTY_TYPE_NUMBER); JSONUtils.write(writer, PROPERTY_VALUE, value); } else if (value instanceof Date) { JSONUtils.write(writer, PROPERTY_TYPE, PROPERTY_TYPE_DATETIME); JSONUtils.write(writer, PROPERTY_VALUE, JSONDateUtils.toString((Date) value)); } else if (value instanceof String) { JSONUtils.write(writer, PROPERTY_TYPE, PROPERTY_TYPE_STRING); JSONUtils.write(writer, PROPERTY_VALUE, value); } else { throw new JSONException("Invalid value type"); } }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, TYPE, getType()); JSONUtils.write(writer, MESSAGE, getMessage()); JSONUtils.write(writer, STACK_TRACE, getStackTrace()); JSONUtils.writeArray(writer, FRAMES, getFrames()); JSONUtils.writeArray(writer, INNER_EXCEPTIONS, getInnerExceptions()); JSONUtils.write(writer, WRAPPER_SDK_NAME, getWrapperSdkName()); }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, WRAPPER_SDK_VERSION, getWrapperSdkVersion()); JSONUtils.write(writer, WRAPPER_SDK_NAME, getWrapperSdkName()); JSONUtils.write(writer, WRAPPER_RUNTIME_VERSION, getWrapperRuntimeVersion()); JSONUtils.write(writer, LIVE_UPDATE_RELEASE_LABEL, getLiveUpdateReleaseLabel()); JSONUtils.write(writer, LIVE_UPDATE_DEPLOYMENT_KEY, getLiveUpdateDeploymentKey()); JSONUtils.write(writer, LIVE_UPDATE_PACKAGE_HASH, getLiveUpdatePackageHash()); }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, PROVIDER, getProvider()); }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, LOCAL_ID, getLocalId()); }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, TZ, getTz()); }
@Override public void write(JSONStringer writer) throws JSONException { super.write(writer); JSONUtils.write(writer, ID, getId()); JSONUtils.write(writer, ERROR_ID, getErrorId()); JSONUtils.write(writer, CONTENT_TYPE, getContentType()); JSONUtils.write(writer, FILE_NAME, getFileName()); JSONUtils.write(writer, DATA, Base64.encodeToString(getData(), Base64.NO_WRAP)); }
@Override public void write(JSONStringer writer) throws JSONException { super.write(writer); JSONUtils.write(writer, ID, getId()); JSONUtils.write(writer, PROCESS_ID, getProcessId()); JSONUtils.write(writer, PROCESS_NAME, getProcessName()); JSONUtils.write(writer, PARENT_PROCESS_ID, getParentProcessId()); JSONUtils.write(writer, PARENT_PROCESS_NAME, getParentProcessName()); JSONUtils.write(writer, ERROR_THREAD_ID, getErrorThreadId()); JSONUtils.write(writer, ERROR_THREAD_NAME, getErrorThreadName()); JSONUtils.write(writer, FATAL, getFatal()); JSONUtils.write(writer, APP_LAUNCH_TIMESTAMP, JSONDateUtils.toString(getAppLaunchTimestamp())); JSONUtils.write(writer, ARCHITECTURE, getArchitecture()); }
@Override public void write(JSONStringer writer) throws JSONException { /* Serialize part B before. */ JSONUtils.write(writer, BASE_TYPE, mProperties.optString(BASE_TYPE, null)); JSONUtils.write(writer, BASE_DATA, mProperties.optJSONObject(BASE_DATA)); /* Then part C. */ JSONArray names = mProperties.names(); if (names != null) { for (int i = 0; i < names.length(); i++) { String name = names.getString(i); if (!name.equals(BASE_TYPE) && !name.equals(BASE_DATA)) { writer.key(name).value(mProperties.get(name)); } } } }
@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(); } }
private static void writeProperties(JSONStringer writer, Map<String, Object> properties) throws JSONException { if (properties != null) { writer.key(PROPERTIES).array(); for (Map.Entry<String, Object> property : properties.entrySet()) { writer.object(); JSONUtils.write(writer, PROPERTY_NAME, property.getKey()); writePropertyValue(writer, property.getValue()); writer.endObject(); } writer.endArray(); } else { throw new JSONException("Properties cannot be null"); } }
@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")); }
@Override public void write(JSONStringer writer) throws JSONException { super.write(writer); writer.key(SDK_NAME).value(getSdkName()); writer.key(SDK_VERSION).value(getSdkVersion()); writer.key(MODEL).value(getModel()); writer.key(OEM_NAME).value(getOemName()); writer.key(OS_NAME).value(getOsName()); writer.key(OS_VERSION).value(getOsVersion()); JSONUtils.write(writer, OS_BUILD, getOsBuild()); JSONUtils.write(writer, OS_API_LEVEL, getOsApiLevel()); writer.key(LOCALE).value(getLocale()); writer.key(TIME_ZONE_OFFSET).value(getTimeZoneOffset()); writer.key(SCREEN_SIZE).value(getScreenSize()); writer.key(APP_VERSION).value(getAppVersion()); JSONUtils.write(writer, CARRIER_NAME, getCarrierName()); JSONUtils.write(writer, CARRIER_COUNTRY, getCarrierCountry()); writer.key(APP_BUILD).value(getAppBuild()); JSONUtils.write(writer, APP_NAMESPACE, getAppNamespace()); }