/*
   * (non-Javadoc)
   *
   * @see com.google.gson.TypeAdapter#write(com.google.gson.stream.JsonWriter, java.lang.Object)
   */
  @Override
  public void write(JsonWriter writer, SpeechTimestamp speechTimestamp) throws IOException {
    writer.beginArray();

    writer.value(speechTimestamp.getWord());
    writer.value(speechTimestamp.getStartTime());
    writer.value(speechTimestamp.getEndTime());

    writer.endArray();
    writer.flush();
  }
  /*
   * (non-Javadoc)
   *
   * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
   */
  @Override
  public SpeechTimestamp read(JsonReader reader) throws IOException {
    if (reader.peek() == JsonToken.NULL) {
      reader.nextNull();
      return null;
    }

    String word = null;
    Double startTime = null, endTime = null;

    reader.beginArray();

    if (reader.peek() == JsonToken.STRING) {
      word = reader.nextString();
    }
    if (reader.peek() == JsonToken.NUMBER) {
      startTime = reader.nextDouble();
    }
    if (reader.peek() == JsonToken.NUMBER) {
      endTime = reader.nextDouble();
    }

    reader.endArray();

    SpeechTimestamp speechTimestamp = new SpeechTimestamp();

    if (word != null) {
      speechTimestamp.setWord(word);
    }

    if (startTime != null) {
      speechTimestamp.setStartTime(startTime);
    }

    if (endTime != null) {
      speechTimestamp.setEndTime(endTime);
    }

    return speechTimestamp;
  }