package com.youcruit.onfido.api.serialization;

import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.neovisionaries.i18n.CountryCode;

public class CountryCodeTypeAdapter implements JsonSerializer<CountryCode>, JsonDeserializer<CountryCode> {

    @Override
    public CountryCode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
	return CountryCode.valueOf(json.getAsString());
    }

    @Override
    public JsonElement serialize(CountryCode src, Type typeOfSrc, JsonSerializationContext context) {
	return context.serialize(src.getAlpha3());
    }
}

@@ -71,16 +71,41 @@
 ct.Type;
+%0Aimport java.util.Locale;
 %0A%0Aimport
@@ -656,16 +656,63 @@
 ption %7B%0A
+%09if (json.isJsonNull()) %7B%0A%09    return null;%0A%09%7D%0A
 %09return 
@@ -727,15 +727,17 @@
 ode.
-valueOf
+getByCode
 (jso
@@ -751,16 +751,39 @@
 String()
+.toUpperCase(Locale.US)
 );%0A    %7D

Use correct method for retrieving country code