exchange.apexpro.connector.impl.utils.json.CostBigDecimalAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apexpro-connector-java Show documentation
Show all versions of apexpro-connector-java Show documentation
A lightweight library to ApeX-Protocol
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);
}
}