Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Helper function for casting / parsing Record when using Skygear
import java.util.Map;
import io.skygear.skygear.Record;
public class RecordHelper {
public static <T> T toObject(Record record, Class<T> classOfT) {
Gson gson = new Gson();
String json = toJson(record);
return gson.fromJson(json, classOfT);
public static String toJson(Record record) {
Gson gson = new Gson();
Map<String, Object> root = record.getData();
Map<String, Object> firstLevel = record.getTransient();
for (String key : firstLevel.keySet()) {
Record r = (Record) firstLevel.get(key);
root.put(key, r.getData());
return gson.toJson(root);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.