@UnstableApi
public final class JsonUtil


Utilities for working with JSON

Summary

Public methods

static @Nullable JSONObject

Creates a JSONObject from the Exception.

static JSONObject

Creates a JSONObject from the ExportResult.

static JSONObject

Returns a JSONObject containing device specific details from Build, including manufacturer, model, SDK version and build fingerprint.

static JSONArray

Creates a JSONArray from processed inputs.

Public methods

exceptionAsJsonObject

public static @Nullable JSONObject exceptionAsJsonObject(@Nullable Exception exception)

Creates a JSONObject from the Exception.

If the exception is an ExportException, errorCode is included.

Parameters
@Nullable Exception exception

The Exception.

Returns
@Nullable JSONObject

The JSONObject containing the exception details, or null if the exception was null.

Throws
org.json.JSONException

if this method attempts to create a JSON with null key.

exportResultAsJsonObject

public static JSONObject exportResultAsJsonObject(ExportResult exportResult)

Creates a JSONObject from the ExportResult.

Parameters
ExportResult exportResult

The ExportResult.

Returns
JSONObject

The JSONObject describing the exportResult.

Throws
org.json.JSONException

if this method attempts to create a JSON with null key.

getDeviceDetailsAsJsonObject

public static JSONObject getDeviceDetailsAsJsonObject()

Returns a JSONObject containing device specific details from Build, including manufacturer, model, SDK version and build fingerprint.

processedInputsAsJsonArray

public static JSONArray processedInputsAsJsonArray(
    ImmutableList<ExportResult.ProcessedInput> processedInputs
)

Creates a JSONArray from processed inputs.

Parameters
ImmutableList<ExportResult.ProcessedInput> processedInputs

The list of ExportResult.ProcessedInput instances.

Returns
JSONArray

A JSONArray containing JSONObject instances representing the instances.

Throws
org.json.JSONException

if this method attempts to create a JSON with null key.