use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.
the class BigNumbersTest method _testBigDecimal.
private void _testBigDecimal(BigDecimal expValue) throws Exception {
final ByteArrayOutputStream sourceBytes = new ByteArrayOutputStream();
final CBORGenerator sourceGen = cborGenerator(sourceBytes);
sourceGen.writeStartObject();
sourceGen.writeName("a");
sourceGen.writeNumber(expValue);
sourceGen.writeEndObject();
sourceGen.close();
byte[] b = sourceBytes.toByteArray();
// but verify that the original content can be parsed
CBORParser parser = cborParser(b);
assertToken(JsonToken.START_OBJECT, parser.nextToken());
assertToken(JsonToken.PROPERTY_NAME, parser.nextToken());
assertEquals("a", parser.currentName());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, parser.nextToken());
assertEquals(expValue, parser.getDecimalValue());
assertToken(JsonToken.END_OBJECT, parser.nextToken());
parser.close();
}
use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.
the class ParseIncompleteArray240Test method testIncompleteMarkerBasedArray.
public void testIncompleteMarkerBasedArray() throws Exception {
final byte[] input = { (byte) 0x9F };
try (CBORParser p = cborParser(F, input)) {
assertToken(JsonToken.START_ARRAY, p.nextToken());
try {
p.nextToken();
fail("Should NOT pass");
} catch (StreamReadException e) {
verifyException(e, "Unexpected end-of-input in Array value: expected an element or ");
}
}
}
use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.
the class ParseIncompleteArray240Test method testIncompleteFixedSizeArray.
// [dataformats-binary#240]
public void testIncompleteFixedSizeArray() throws Exception {
final byte[] input = { (byte) 0x84 };
try (CBORParser p = cborParser(F, input)) {
assertToken(JsonToken.START_ARRAY, p.nextToken());
try {
p.nextToken();
fail("Should NOT pass");
} catch (StreamReadException e) {
verifyException(e, "Unexpected end-of-input in Array value: expected 4 more");
}
}
}
use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.
the class ParseInvalidUTF8String236Test method testShortString236Original.
// [dataformats-binary#236]: Original version; broken UTF-8 all around.
// but gets hit by end-of-input only (since content not validated)
public void testShortString236Original() throws Exception {
final byte[] input = { 0x66, (byte) 0xef, 0x7d, 0x7d, 0xa, 0x2d, (byte) 0xda };
try (CBORParser p = cborParser(input)) {
assertToken(JsonToken.VALUE_STRING, p.nextToken());
try {
String str = p.getText();
fail("Should have failed, did not, String = '" + str + "'");
} catch (StreamReadException e) {
verifyException(e, "Invalid UTF-8 middle byte 0x7d");
}
}
}
use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.
the class ParseIncompleteArray240Test method testIncompleteMarkerBasedObject.
public void testIncompleteMarkerBasedObject() throws Exception {
final byte[] input = { (byte) 0xBF };
try (CBORParser p = cborParser(F, input)) {
assertToken(JsonToken.START_OBJECT, p.nextToken());
try {
p.nextToken();
fail("Should NOT pass");
} catch (StreamReadException e) {
verifyException(e, "Unexpected end-of-input in Object value: expected a property or close marker");
}
}
}
Aggregations