package com.cloudycrew.cloudycar.utils;

import com.cloudycrew.cloudycar.models.requests.AcceptedRequest;
import com.cloudycrew.cloudycar.models.requests.CompletedRequest;
import com.cloudycrew.cloudycar.models.requests.ConfirmedRequest;
import com.cloudycrew.cloudycar.models.requests.PendingRequest;
import com.cloudycrew.cloudycar.models.requests.Request;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;

/**
 * Created by George on 2016-10-25.
 */

public class RequestUtils {
    private static JsonDeserializer<Request> getRequestDeserializer() {
        return new SubclassDeserializer.Builder<Request>()
                .setTypeFieldName("requestType")
                .registerRequestType(PendingRequest.TYPE_NAME, PendingRequest.class)
                .registerRequestType(AcceptedRequest.TYPE_NAME, AcceptedRequest.class)
                .registerRequestType(ConfirmedRequest.TYPE_NAME, ConfirmedRequest.class)
                .registerRequestType(CompletedRequest.TYPE_NAME, CompletedRequest.class)
                .build();
    }

    public static Gson getGson() {
        return new GsonBuilder().registerTypeAdapter(Request.class, getRequestDeserializer()).create();
    }
}

Add request utils for getting a gson instance that can handle deserializing requests
Add request utils for getting a gson instance that can handle deserializing requests
