Search in sources :

Example 61 with JsonFactory

use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.

the class TestGeneratorClosing method testNoAutoCloseOutputStream.

public void testNoAutoCloseOutputStream() throws Exception {
    JsonFactory f = JsonFactory.builder().disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET).build();
    @SuppressWarnings("resource") MyStream output = new MyStream();
    JsonGenerator g = f.createGenerator(ObjectWriteContext.empty(), output, JsonEncoding.UTF8);
    assertFalse(output.isClosed());
    g.writeNumber(39);
    g.close();
    assertFalse(output.isClosed());
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 62 with JsonFactory

use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.

the class TestNumberParsing method testFloatBoundary146Chars.

public void testFloatBoundary146Chars() throws Exception {
    final char[] arr = new char[50005];
    final JsonFactory f = new JsonFactory();
    for (int i = 500; i != 9000; ++i) {
        java.util.Arrays.fill(arr, 0, i, ' ');
        arr[i] = '-';
        arr[i + 1] = '1';
        arr[i + 2] = 'e';
        arr[i + 3] = '-';
        arr[i + 4] = '1';
        CharArrayReader r = new CharArrayReader(arr, 0, i + 5);
        JsonParser p = f.createParser(ObjectReadContext.empty(), r);
        assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
        p.close();
    }
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 63 with JsonFactory

use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.

the class TestNumberParsing method testFloatBoundary146Bytes.

public void testFloatBoundary146Bytes() throws Exception {
    final byte[] arr = new byte[50005];
    final JsonFactory f = new JsonFactory();
    for (int i = 500; i != 9000; ++i) {
        java.util.Arrays.fill(arr, 0, i, (byte) 0x20);
        arr[i] = '-';
        arr[i + 1] = '1';
        arr[i + 2] = 'e';
        arr[i + 3] = '-';
        arr[i + 4] = '1';
        ByteArrayInputStream in = new ByteArrayInputStream(arr, 0, i + 5);
        JsonParser p = f.createParser(ObjectReadContext.empty(), in);
        assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
        p.close();
    }
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 64 with JsonFactory

use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.

the class TestParserFeatures method _testQuotesRequired.

private void _testQuotesRequired(boolean useStream) throws Exception {
    final String JSON = "{ test : 3 }";
    final String EXP_ERROR_FRAGMENT = "was expecting double-quote to start";
    JsonFactory f = new JsonFactory();
    JsonParser p = useStream ? createParserUsingStream(f, JSON, "UTF-8") : createParserUsingReader(f, JSON);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    try {
        p.nextToken();
    } catch (JsonParseException je) {
        verifyException(je, EXP_ERROR_FRAGMENT);
    } finally {
        p.close();
    }
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 65 with JsonFactory

use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.

the class TestJsonStringEncoder method testQuoteAsUTF8.

public void testQuoteAsUTF8() throws Exception {
    // In this case, let's actually use existing JsonGenerator to produce expected values
    JsonFactory f = new JsonFactory();
    JsonStringEncoder encoder = new JsonStringEncoder();
    int[] lengths = new int[] { 5, 19, 200, 7000, 21000, 37000 };
    for (int length : lengths) {
        String str = generateRandom(length);
        StringWriter sw = new StringWriter(length * 2);
        JsonGenerator jgen = f.createGenerator(ObjectWriteContext.empty(), sw);
        jgen.writeString(str);
        jgen.close();
        String encoded = sw.toString();
        // ok, except need to remove surrounding quotes
        encoded = encoded.substring(1, encoded.length() - 1);
        byte[] expected = encoded.getBytes("UTF-8");
        byte[] actual = encoder.quoteAsUTF8(str);
        assertArrayEquals(expected, actual);
    }
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Aggregations

JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)137 AsyncReaderWrapper (com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)5 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)3 JsonParser (com.fasterxml.jackson.core.JsonParser)2 SerializedString (com.fasterxml.jackson.core.io.SerializedString)2 NonBlockingJsonParserBase (com.fasterxml.jackson.core.json.async.NonBlockingJsonParserBase)2 ByteQuadsCanonicalizer (com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)2 MinimalPrettyPrinter (com.fasterxml.jackson.core.util.MinimalPrettyPrinter)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 BigDecimal (java.math.BigDecimal)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 StringWriter (java.io.StringWriter)1 Field (java.lang.reflect.Field)1 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1