aboutsummaryrefslogtreecommitdiff
path: root/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetObjectConverter.java
diff options
context:
space:
mode:
authorfrankfeng <frankfeng@google.com>2022-01-05 23:53:39 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-01-05 23:53:39 +0000
commit7151acd88deae8709cb212b20494a4c38ecc8263 (patch)
treedaa905c2cab4f307d9342908fc85ec54ab73bab3 /third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetObjectConverter.java
parenta18b21585728971688495dbe384c61b0332c8ce1 (diff)
parenta3c4e39314251b98b0ee70da2bb63dbc52137ac7 (diff)
downloadmobly-snippet-lib-7151acd88deae8709cb212b20494a4c38ecc8263.tar.gz
Merge remote-tracking branch 'aosp/upstream-master' into merge am: 22b92531fc am: 7902e5747e am: a3c4e39314
Original change: https://android-review.googlesource.com/c/platform/external/mobly-snippet-lib/+/1932020 Change-Id: Id8702566f1ba34c44a867e3f61f4af94b7b4006d
Diffstat (limited to 'third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetObjectConverter.java')
-rw-r--r--third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetObjectConverter.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetObjectConverter.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetObjectConverter.java
new file mode 100644
index 0000000..b9a101b
--- /dev/null
+++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetObjectConverter.java
@@ -0,0 +1,39 @@
+package com.google.android.mobly.snippet;
+
+import java.lang.reflect.Type;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Interface for a converter that serializes and de-serializes objects.
+ *
+ * <p>Classes implementing this interface are meant to provide custom serialization/de-serialization
+ * logic for complex types.
+ *
+ * <p>Serialization here means converting a Java object to {@link JSONObject}, which can be
+ * transported over Snippet's Rpc protocol. De-serialization is this process in reverse.
+ */
+public interface SnippetObjectConverter {
+ /**
+ * Serializes a complex type object to {@link JSONObject}.
+ *
+ * <p>Return null to signify the complex type is not supported.
+ *
+ * @param object The object to convert to "serialize".
+ * @return A JSONObject representation of the input object, or `null` if the input object type
+ * is not supported.
+ * @throws JSONException
+ */
+ JSONObject serialize(Object object) throws JSONException;
+
+ /**
+ * Deserializes a {@link JSONObject} to a Java complex type object.
+ *
+ * @param jsonObject A {@link JSONObject} passed from the Rpc client.
+ * @param type The expected {@link Type} of the Java object.
+ * @return A Java object of the specified {@link Type}, or `null` if the {@link Type} is not
+ * supported.
+ * @throws JSONException
+ */
+ Object deserialize(JSONObject jsonObject, Type type) throws JSONException;
+}