@Override
  public Object next() {
    // Return empty string if size of json string is zero or if number of elements is zero.
    if (_jsonStringLength == 0 || _jsonStringLength / DEFAULT_JSON_ELEMENT_LENGTH == 0) {
      return "{}";
    }

    // Create JSON string { "<character>":<integer>, "<character>":<integer>, ...} as per length specified. Escape
    // comma's in JSON since comma is used as delimiter in CSV data file that will be used to generate segment.
    StringBuffer jsonBuffer = new StringBuffer();
    int elementCount = _jsonStringLength / DEFAULT_JSON_ELEMENT_LENGTH;
    jsonBuffer.append("{");
    for (int i = 0; i < elementCount; i++) {
      if (jsonBuffer.length() > 1) {
        jsonBuffer.append("\\,");
      }
      String item = "\"" + (char) ('a' + _random.nextInt(26)) + "\":" + _random.nextInt(10);
      jsonBuffer.append(item);
    }

    return jsonBuffer.append("}").toString();
  }
@Test
  public void testNext()
      throws IOException {
    // JsonGenerator generates empty json when size is less than JsonGenerator.DEFAULT_JSON_ELEMENT_LENGTH
    JsonGenerator jsonGenerator1 = new JsonGenerator(0);
    Assert.assertEquals(jsonGenerator1.next(), "{}");

    JsonGenerator jsonGenerator2 = new JsonGenerator(4);
    Assert.assertEquals(jsonGenerator2.next(), "{}");

    JsonGenerator jsonGenerator3 = new JsonGenerator(8);
    checkJson((String) jsonGenerator3.next(), 8);

    JsonGenerator jsonGenerator4 = new JsonGenerator(20);
    checkJson((String) jsonGenerator4.next(), 20);
  }