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

exchange.apexpro.connector.impl.utils.json.CostBigDecimalAdapter Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package exchange.apexpro.connector.impl.utils.json;

import com.google.gson.*;

import java.lang.reflect.Type;
import java.math.BigDecimal;

public class CostBigDecimalAdapter implements JsonDeserializer, JsonSerializer {

    public BigDecimal deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        BigDecimal cost;
        try {
            cost = new BigDecimal(json.getAsString());
        } catch (NumberFormatException e) {
            cost = new BigDecimal(0);
        }
        return cost;
    }

    @Override
    public JsonElement serialize(BigDecimal src, Type type, JsonSerializationContext jsonSerializationContext) {
        return new JsonPrimitive(src);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy