package org.wikipedia.json;


import android.graphics.Color;
import android.net.Uri;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import org.wikipedia.zero.ZeroConfig;

import java.io.IOException;

class ZeroConfigTypeAdapter extends TypeAdapter<ZeroConfig> {
    @Override
    public void write(JsonWriter out, ZeroConfig value) throws IOException {
        out.value(value.toString());
    }

    @Override
    public ZeroConfig read(JsonReader in) throws IOException, NumberFormatException {
        ZeroConfig result = new ZeroConfig();
        in.beginObject();
        while (in.hasNext()) {
            String field = in.nextName();
            String value = in.nextString();
            switch (field) {
                case "message":
                    result.setMessage(value);
                    break;
                case "background":
                    result.setBackground(Color.parseColor(value));
                    break;
                case "foreground":
                    result.setForeground(Color.parseColor(value));
                    break;
                case "exitTitle":
                    result.setExitTitle(value);
                    break;
                case "exitWarning":
                    result.setExitWarning(value);
                    break;
                case "partnerInfoText":
                    result.setPartnerInfoText(value);
                    break;
                case "partnerInfoUrl":
                    result.setPartnerInfoUrl(Uri.parse(value));
                    break;
                case "bannerUrl":
                    result.setBannerUrl(Uri.parse(value));
                    break;
                default:
                    break;
            }
        }
        in.endObject();
        return result;
    }
}

@@ -335,36 +335,32 @@
  %7B%0A    @Override
-%0A   
  public void wri
@@ -429,34 +429,48 @@
     
-out.value(value.toString()
+throw new UnsupportedOperationException(
 );%0A 
@@ -1879,9 +1879,8 @@
 %0A    %7D%0A%7D
-%0A

throw Exception when trying to marshal ZeroConfig