Java tutorial
/* * Copyright (c) 2017 ?. All Rights Reserved. * Use of this source code is governed by a Shanghai Unovo Information Technology Co.,Ltd license * that can be found in the LICENSE file in the root of the web site. * * http://www.unovo.com.cn * * An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. * */ package com.unovo.frame.utils.gson.deserializer; import com.unovo.frame.utils.log.Logger; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import java.lang.reflect.Type; /** * Created by Aeatho on 2016/12/29 16:59 * * Prject: unovo-guest-app * Description: * email: aeatho@gmail.com */ public class FloatJsonDeserializer implements JsonDeserializer<Float> { @Override public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try { return json.getAsFloat(); } catch (Exception e) { Logger.i("FloatJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : "")); return 0F; } } }