Search in sources :

Example 6 with CBORParser

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();
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CBORGenerator(com.fasterxml.jackson.dataformat.cbor.CBORGenerator)

Example 7 with CBORParser

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 ");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 8 with CBORParser

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");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 9 with CBORParser

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");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 10 with CBORParser

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");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Aggregations

CBORParser (com.fasterxml.jackson.dataformat.cbor.CBORParser)22 StreamReadException (com.fasterxml.jackson.core.exc.StreamReadException)9 CBORGenerator (com.fasterxml.jackson.dataformat.cbor.CBORGenerator)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonLocation (com.fasterxml.jackson.core.JsonLocation)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 PublicKey (com.quorum.tessera.encryption.PublicKey)1 Fido2RuntimeException (io.jans.fido2.exception.Fido2RuntimeException)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1