io.gitee.huangguiming.Imcode.adapter.IMErrorAdapter Maven / Gradle / Ivy
package io.gitee.huangguiming.Imcode.adapter;
import com.google.gson.*;
import io.gitee.huangguiming.Imcode.exception.IMError;
import io.gitee.huangguiming.Imcode.utils.GsonHelper;
import java.lang.reflect.Type;
public class IMErrorAdapter implements JsonDeserializer {
@Override
public IMError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
IMError.IMErrorBuilder errorBuilder = IMError.builder();
JsonObject wxErrorJsonObject = json.getAsJsonObject();
if (wxErrorJsonObject.get("ErrorCode") != null && !wxErrorJsonObject.get("ErrorCode").isJsonNull()) {
errorBuilder.ErrorCode(GsonHelper.getAsPrimitiveInt(wxErrorJsonObject.get("ErrorCode")));
}
if (wxErrorJsonObject.get("ErrorInfo") != null && !wxErrorJsonObject.get("ErrorInfo").isJsonNull()) {
errorBuilder.ErrorInfo(GsonHelper.getAsString(wxErrorJsonObject.get("ErrorInfo")));
}
errorBuilder.ErrorInfo(json.toString());
return errorBuilder.build();
}
}