All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gitee.huangguiming.Imcode.adapter.IMErrorAdapter Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy