jp.gopay.sdk.utils.EnumConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gopay-java-sdk Show documentation
Show all versions of gopay-java-sdk Show documentation
Official Gyro-n Payments Java SDK
package jp.gopay.sdk.utils;
import com.google.gson.annotations.SerializedName;
import retrofit2.Converter;
import retrofit2.Converter.Factory;
import retrofit2.Retrofit;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
public class EnumConverter extends Factory {
@Override
public Converter, String> stringConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
class GoPayEnumConverter implements Converter{
@Override
public String convert(Enum e) throws IOException {
String value = null;
try {
value = e.getClass().getField(e.name()).getAnnotation(SerializedName.class).value();
}
catch(NoSuchFieldException exception){
exception.printStackTrace();
}
return value;
}
}
Converterconverter = null;
if(type instanceof Class> && ((Class>)type).isEnum()){
converter = new GoPayEnumConverter();
}
return converter;
}
}