package org.knowm.xchange.yobit.dto.marketdata;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.knowm.xchange.yobit.dto.marketdata.YoBitOrderBook.YoBitOrderBookDeserializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

@JsonDeserialize(using = YoBitOrderBookDeserializer.class)
public class YoBitOrderBook {

  private List<YoBitAsksBidsData> asks;
  private List<YoBitAsksBidsData> bids;

  public YoBitOrderBook(List<YoBitAsksBidsData> asks, List<YoBitAsksBidsData> bids) {
    this.asks = asks;
    this.bids = bids;
  }

  public List<YoBitAsksBidsData> getAsks() {
    return asks;
  }

  public List<YoBitAsksBidsData> getBids() {
    return bids;
  }

  static class YoBitOrderBookDeserializer extends JsonDeserializer<YoBitOrderBook> {

    @Override
    public YoBitOrderBook deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {

      ObjectCodec oc = jp.getCodec();
      JsonNode node = oc.readTree(jp);

      List<YoBitAsksBidsData> asks = parse(node.get("asks"));
      List<YoBitAsksBidsData> bids = parse(node.get("bids"));

      return new YoBitOrderBook(asks, bids);
    }

    private List<YoBitAsksBidsData> parse(JsonNode nodeArray) {
      List<YoBitAsksBidsData> res = new ArrayList<>();

      for (JsonNode jsonNode : nodeArray) {
        res.add(new YoBitAsksBidsData(BigDecimal.valueOf(jsonNode.get(1).asDouble()), BigDecimal.valueOf(jsonNode.get(0).asDouble())));
      }

      return res;
    }
  }
}
@@ -46,207 +46,8 @@
 a;%0A%0A
-import java.io.IOException;%0Aimport java.math.BigDecimal;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.knowm.xchange.yobit.dto.marketdata.YoBitOrderBook.YoBitOrderBookDeserializer;%0A%0A
 impo
@@ -425,16 +425,214 @@
 rialize;
+%0Aimport org.knowm.xchange.yobit.dto.marketdata.YoBitOrderBook.YoBitOrderBookDeserializer;%0A%0Aimport java.io.IOException;%0Aimport java.math.BigDecimal;%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0A%0A@JsonD
@@ -1665,24 +1665,56 @@
 yList%3C%3E();%0A%0A
+      if(nodeArray != null) %7B%0A  
       for (J
@@ -1741,24 +1741,26 @@
 odeArray) %7B%0A
+  
         res.
@@ -1879,24 +1879,34 @@
 ouble())));%0A
+        %7D%0A
       %7D%0A%0A   

fix NPE