blob: eea8831d3fcf30487aedc798f11e8a1d3445600e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package com.google.android.mobly.snippet.example6;
import com.google.android.mobly.snippet.SnippetObjectConverter;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Type;
/**
* Example showing how to supply custom object converter to Mobly Snippet Lib.
*/
public class ExampleObjectConverter implements SnippetObjectConverter {
@Override
public JSONObject serialize(Object object) throws JSONException {
JSONObject result = new JSONObject();
if (object instanceof CustomType) {
CustomType input = (CustomType) object;
result.put("Value", input.getMyValue());
return result;
}
return null;
}
@Override
public Object deserialize(JSONObject jsonObject, Type type) throws JSONException {
if (type == CustomType.class) {
return new CustomType(jsonObject.getString("Value"));
}
return null;
}
}
|