com.unovo.frame.utils.gson.deserializer.DoubleJsonDeserializer.java Source code

Java tutorial

Introduction

Here is the source code for com.unovo.frame.utils.gson.deserializer.DoubleJsonDeserializer.java

Source

/*
 * 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:58
 *
 * Prject: unovo-guest-app
 * Description:
 * email: aeatho@gmail.com
 */
public class DoubleJsonDeserializer implements JsonDeserializer<Double> {
    @Override
    public Double deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
            throws JsonParseException {
        try {
            return json.getAsDouble();
        } catch (Exception e) {
            Logger.i("DoubleJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
            return 0D;
        }
    }
}