packagecom.ydl.ydlnet.builder.gson;importcom.google.gson.*;importjava.lang.reflect.Type;/** * Created by haorui on 2019-09-02 . * Des: 定义为int类型,如果后台返回""或者null,则返回0 */publicclassIntegerDefault0AdapterimplementsJsonSerializer<Integer>,JsonDeserializer<Integer>{@OverridepublicIntegerdeserialize(JsonElementjson,TypetypeOfT,JsonDeserializationContextcontext)throwsJsonParseException{try{if(json.getAsString().equals("")||json.getAsString().equals("null")){return0;}}catch(Exceptionignore){}try{returnjson.getAsInt();}catch(NumberFormatExceptione){thrownewJsonSyntaxException(e);}}@OverridepublicJsonElementserialize(Integersrc,TypetypeOfSrc,JsonSerializationContextcontext){returnnewJsonPrimitive(src);}}