Search in sources :

Example 21 with SmileGenerator

use of com.fasterxml.jackson.dataformat.smile.SmileGenerator in project jackson-dataformats-binary by FasterXML.

the class TestGeneratorNumbers method testDoubles.

public void testDoubles() throws Exception {
    // double length is fixed, 11 bytes
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SmileGenerator gen = _smileGenerator(out, false);
    gen.writeNumber(0.125);
    gen.close();
    assertEquals(11, out.toByteArray().length);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) SmileGenerator(com.fasterxml.jackson.dataformat.smile.SmileGenerator)

Example 22 with SmileGenerator

use of com.fasterxml.jackson.dataformat.smile.SmileGenerator in project jackson-dataformats-binary by FasterXML.

the class TestGeneratorSymbols method testSharedNameSimple.

/**
 * Simple test to verify that second reference will not output new String, but
 * rather references one output earlier.
 */
public void testSharedNameSimple() throws Exception {
    // false, no header (or frame marker)
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SmileGenerator gen = _smileGenerator(out, false);
    gen.writeStartArray();
    gen.writeStartObject();
    gen.writeNumberProperty("abc", 1);
    gen.writeEndObject();
    gen.writeStartObject();
    gen.writeNumberProperty("abc", 2);
    gen.writeEndObject();
    gen.writeEndArray();
    gen.close();
    byte[] result = out.toByteArray();
    assertEquals(13, result.length);
}
Also used : SmileGenerator(com.fasterxml.jackson.dataformat.smile.SmileGenerator)

Example 23 with SmileGenerator

use of com.fasterxml.jackson.dataformat.smile.SmileGenerator in project jackson-dataformats-binary by FasterXML.

the class TestGeneratorWithRawUtf8 method doTestIssue492.

/*
    /**********************************************************
    /* Helper methods
    /**********************************************************
     */
private void doTestIssue492(boolean asUtf8String) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SmileGenerator generator = (SmileGenerator) MAPPER.createGenerator(out);
    generator.writeStartObject();
    generator.writeName("name");
    if (asUtf8String) {
        byte[] text = "PojoFoo".getBytes("ASCII");
        generator.writeUTF8String(text, 0, text.length);
    } else {
        generator.writeString("PojoFoo");
    }
    generator.writeName("collection");
    generator.writeStartObject();
    generator.writeName("v");
    generator.writeStartArray();
    if (asUtf8String) {
        byte[] text = "1".getBytes("ASCII");
        generator.writeUTF8String(text, 0, text.length);
    } else {
        generator.writeString("1");
    }
    generator.writeEndArray();
    generator.writeEndObject();
    generator.writeEndObject();
    generator.close();
    byte[] data = out.toByteArray();
    ByteArrayInputStream in = new ByteArrayInputStream(data);
    SmileParser parser = (SmileParser) MAPPER.createParser(in);
    assertToken(parser.nextToken(), JsonToken.START_OBJECT);
    assertToken(parser.nextToken(), JsonToken.PROPERTY_NAME);
    assertEquals(parser.currentName(), "name");
    assertToken(parser.nextToken(), JsonToken.VALUE_STRING);
    assertEquals(parser.getText(), "PojoFoo");
    assertToken(parser.nextToken(), JsonToken.PROPERTY_NAME);
    assertEquals(parser.currentName(), "collection");
    assertToken(parser.nextToken(), JsonToken.START_OBJECT);
    assertToken(parser.nextToken(), JsonToken.PROPERTY_NAME);
    assertEquals("Should have property with name 'v'", parser.currentName(), "v");
    assertToken(parser.nextToken(), JsonToken.START_ARRAY);
    assertToken(parser.nextToken(), JsonToken.VALUE_STRING);
    assertEquals("Should get String value '1'", parser.getText(), "1");
    assertToken(parser.nextToken(), JsonToken.END_ARRAY);
    assertToken(parser.nextToken(), JsonToken.END_OBJECT);
    assertToken(parser.nextToken(), JsonToken.END_OBJECT);
    parser.close();
}
Also used : SmileParser(com.fasterxml.jackson.dataformat.smile.SmileParser) SmileGenerator(com.fasterxml.jackson.dataformat.smile.SmileGenerator)

Aggregations

SmileGenerator (com.fasterxml.jackson.dataformat.smile.SmileGenerator)23 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 BigDecimal (java.math.BigDecimal)4 JsonParser (com.fasterxml.jackson.core.JsonParser)2 SmileFactory (com.fasterxml.jackson.dataformat.smile.SmileFactory)2 SmileParser (com.fasterxml.jackson.dataformat.smile.SmileParser)2 StreamReadException (com.fasterxml.jackson.core.exc.StreamReadException)1 BigInteger (java.math.BigInteger)1