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