public void testBigDecimal() throws IOException {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    BigDecimal in = new BigDecimal("32599.00001");
    SmileGenerator g = smileGenerator(bo, false);
    g.writeNumber(in);
    g.close();
    byte[] data = bo.toByteArray();
    SmileParser p = _smileParser(data);
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(JsonParser.NumberType.BIG_DECIMAL, p.getNumberType());
    assertEquals(BigDecimal.class, p.getNumberValue().getClass());
    assertEquals(in, p.getDecimalValue());
    p.close();

    // second test; verify skipping works
    bo = new ByteArrayOutputStream();
    g = smileGenerator(bo, false);
    g.writeStartArray();
    g.writeNumber(in);
    g.writeEndArray();
    g.close();
    data = bo.toByteArray();
    p = _smileParser(data);
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertToken(JsonToken.END_ARRAY, p.nextToken());
    assertNull(p.nextToken());
    p.close();
  }
  public void testBigInteger() throws IOException {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    BigInteger in = new BigInteger(String.valueOf(Long.MIN_VALUE) + "0012575934");
    SmileGenerator g = smileGenerator(bo, false);
    g.writeNumber(in);
    g.close();
    byte[] data = bo.toByteArray();
    SmileParser p = _smileParser(data);
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonParser.NumberType.BIG_INTEGER, p.getNumberType());
    assertEquals(BigInteger.class, p.getNumberValue().getClass());
    assertEquals(in, p.getBigIntegerValue());
    p.close();

    // second test; verify skipping works
    bo = new ByteArrayOutputStream();
    g = smileGenerator(bo, false);
    g.writeStartArray();
    g.writeNumber(in);
    g.writeEndArray();
    g.close();
    data = bo.toByteArray();
    p = _smileParser(data);
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertToken(JsonToken.END_ARRAY, p.nextToken());
    assertNull(p.nextToken());
    p.close();
  }
  public void testObjectWithDoubles() throws IOException {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    SmileGenerator g = smileGenerator(bo, false);
    g.writeStartObject();
    g.writeNumberField("x", 0.5);
    g.writeNumberField("y", 0.01338);
    g.writeEndObject();
    g.close();

    byte[] data = bo.toByteArray();

    // first let's just skip
    SmileParser p = _smileParser(data);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertToken(JsonToken.END_OBJECT, p.nextToken());
    p.close();

    // and then check data too (skip codepath distinct)
    p = _smileParser(data);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("x", p.getText());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(0.5, p.getDoubleValue());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("y", p.getText());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(0.01338, p.getDoubleValue());
    assertToken(JsonToken.END_OBJECT, p.nextToken());
    p.close();
  }
 @Override
 public final byte[] serialize(MediaContent content) throws IOException {
   ByteArrayOutputStream baos = outputStream(content);
   JsonGenerator generator = constructGenerator(baos);
   writeMediaContent(generator, content);
   generator.close();
   return baos.toByteArray();
 }
  public void testDoubles() throws IOException {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    SmileGenerator g = smileGenerator(bo, false);
    double value = -12.0986;
    g.writeNumber(value);
    g.close();
    byte[] data = bo.toByteArray();
    assertEquals(11, data.length);

    SmileParser p = _smileParser(data);
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(JsonParser.NumberType.DOUBLE, p.getNumberType());
    assertEquals(value, p.getDoubleValue());
    p.close();
  }
  public void testFloats() throws IOException {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    SmileGenerator g = smileGenerator(bo, false);
    float value = 0.37f;
    g.writeNumber(value);
    g.close();
    byte[] data = bo.toByteArray();
    assertEquals(6, data.length);

    SmileParser p = _smileParser(data);
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(JsonParser.NumberType.FLOAT, p.getNumberType());
    assertEquals(value, p.getFloatValue());
    p.close();
  }
  public void testArrayWithDoubles() throws IOException {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    SmileGenerator g = smileGenerator(bo, false);
    g.writeStartArray();
    g.writeNumber(0.1f);
    g.writeNumber(0.333);
    g.writeEndArray();
    g.close();
    byte[] data = bo.toByteArray();
    assertEquals(19, data.length);

    SmileParser p = _smileParser(data);
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(JsonParser.NumberType.FLOAT, p.getNumberType());
    assertEquals(0.1f, p.getFloatValue());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(JsonParser.NumberType.DOUBLE, p.getNumberType());
    assertEquals(0.333, p.getDoubleValue());
    assertToken(JsonToken.END_ARRAY, p.nextToken());
    p.close();
  }