// Path: src/main/java/com/cf/data/model/poloniex/deserialize/PoloniexChartDataDeserializer.java
// public class PoloniexChartDataDeserializer implements JsonDeserializer<PoloniexChartData> {
// 
//     @Override
//     public PoloniexChartData deserialize(JsonElement json, Type type, JsonDeserializationContext jdc) throws JsonParseException {
//         JsonObject jo = (JsonObject) json;
//         ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(jo.get("date").getAsLong() * 1000), ZoneOffset.UTC);
//         BigDecimal high = BigDecimal.valueOf(jo.get("high").getAsDouble());
//         BigDecimal low = BigDecimal.valueOf(jo.get("low").getAsDouble());
//         BigDecimal open = BigDecimal.valueOf(jo.get("open").getAsDouble());
//         BigDecimal close = BigDecimal.valueOf(jo.get("close").getAsDouble());
//         BigDecimal volume = BigDecimal.valueOf(jo.get("volume").getAsDouble());
//         BigDecimal quoteVolume = BigDecimal.valueOf(jo.get("quoteVolume").getAsDouble());
//         BigDecimal weightedAverage = BigDecimal.valueOf(jo.get("weightedAverage").getAsDouble());
// 
//         return new PoloniexChartData(date, high, low, open, close, volume, quoteVolume, weightedAverage);
//     }
// 
// }


import com.cf.data.model.poloniex.*;
import com.cf.data.model.poloniex.deserialize.PoloniexChartDataDeserializer;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.stream.Collectors;
package com.cf.data.map.poloniex;



/**
 *
 * @author David
 */
public class PoloniexDataMapper {

    private final Gson gson;

    private final static Logger LOGGER = LogManager.getLogger();
    private final static DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss[.n]").withZone(ZoneOffset.UTC);
    private final static String EMPTY_RESULTS = "[]";
    private final static String INVALID_CHART_DATA_DATE_RANGE_RESULT = "[{\"date\":0,\"high\":0,\"low\":0,\"open\":0,\"close\":0,\"volume\":0,\"quoteVolume\":0,\"weightedAverage\":0}]";
    private final static String INVALID_CHART_DATA_CURRENCY_PAIR_RESULT = "{\"error\":\"Invalid currency pair.\"}";

    public PoloniexDataMapper() {
        gson = new GsonBuilder()
                .registerTypeAdapter(ZonedDateTime.class, new JsonDeserializer<ZonedDateTime>() {
                    @Override
                    public ZonedDateTime deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
                        return ZonedDateTime.parse(json.getAsJsonPrimitive().getAsString(), DTF);
                    }
// Path: src/main/java/com/cf/data/model/poloniex/deserialize/PoloniexChartDataDeserializer.java
// public class PoloniexChartDataDeserializer implements JsonDeserializer<PoloniexChartData> {
// 
//     @Override
//     public PoloniexChartData deserialize(JsonElement json, Type type, JsonDeserializationContext jdc) throws JsonParseException {
//         JsonObject jo = (JsonObject) json;
//         ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(jo.get("date").getAsLong() * 1000), ZoneOffset.UTC);
//         BigDecimal high = BigDecimal.valueOf(jo.get("high").getAsDouble());
//         BigDecimal low = BigDecimal.valueOf(jo.get("low").getAsDouble());
//         BigDecimal open = BigDecimal.valueOf(jo.get("open").getAsDouble());
//         BigDecimal close = BigDecimal.valueOf(jo.get("close").getAsDouble());
//         BigDecimal volume = BigDecimal.valueOf(jo.get("volume").getAsDouble());
//         BigDecimal quoteVolume = BigDecimal.valueOf(jo.get("quoteVolume").getAsDouble());
//         BigDecimal weightedAverage = BigDecimal.valueOf(jo.get("weightedAverage").getAsDouble());
// 
//         return new PoloniexChartData(date, high, low, open, close, volume, quoteVolume, weightedAverage);
//     }
// 
// }


// Path: src/main/java/com/cf/data/map/poloniex/PoloniexDataMapper.java
import com.cf.data.model.poloniex.*;
import com.cf.data.model.poloniex.deserialize.PoloniexChartDataDeserializer;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.stream.Collectors;

package com.cf.data.map.poloniex;



/**
 *
 * @author David
 */
public class PoloniexDataMapper {

    private final Gson gson;

    private final static Logger LOGGER = LogManager.getLogger();
    private final static DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss[.n]").withZone(ZoneOffset.UTC);
    private final static String EMPTY_RESULTS = "[]";
    private final static String INVALID_CHART_DATA_DATE_RANGE_RESULT = "[{\"date\":0,\"high\":0,\"low\":0,\"open\":0,\"close\":0,\"volume\":0,\"quoteVolume\":0,\"weightedAverage\":0}]";
    private final static String INVALID_CHART_DATA_CURRENCY_PAIR_RESULT = "{\"error\":\"Invalid currency pair.\"}";

    public PoloniexDataMapper() {
        gson = new GsonBuilder()
                .registerTypeAdapter(ZonedDateTime.class, new JsonDeserializer<ZonedDateTime>() {
                    @Override
                    public ZonedDateTime deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
                        return ZonedDateTime.parse(json.getAsJsonPrimitive().getAsString(), DTF);
                    }
                }).registerTypeAdapter(PoloniexChartData.class, new PoloniexChartDataDeserializer())