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);
}
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);
}
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();
}
Aggregations