Search in sources :

Example 36 with JsonFactory

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

the class ManualSmallTokenRead method main.

public static void main(String[] args) throws Exception {
    if (args.length != 0) {
        System.err.println("Usage: java ...");
        System.exit(1);
    }
    final JsonFactory f = new JsonFactory();
    final String jsonStr = aposToQuotes("{'data':[true,false,null,false,null,true],'last':true}");
    new ManualSmallTokenRead(f, jsonStr).test("char[]", "byte[]", jsonStr.length());
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 37 with JsonFactory

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

the class AsyncNumberLeadingZeroesTest method _testLeadingZeroesFloat.

public void _testLeadingZeroesFloat(String valueStr, double value) throws Exception {
    // first: verify that we get an exception
    JsonFactory f = new JsonFactory();
    assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS));
    String JSON = valueStr;
    AsyncReaderWrapper p = createParser(f, JSON);
    try {
        p.nextToken();
        p.currentText();
        fail("Should have thrown an exception for doc <" + JSON + ">");
    } catch (JsonParseException e) {
        verifyException(e, "invalid numeric value");
    } finally {
        p.close();
    }
    // and then verify it's ok when enabled
    f = f.rebuild().enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS).build();
    assertTrue(f.isEnabled(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS));
    p = createParser(f, JSON);
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(String.valueOf(value), p.currentText());
    assertEquals(value, p.getDoubleValue());
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 38 with JsonFactory

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

the class AsyncScalarArrayTest method testDoubles.

public void testDoubles() throws IOException {
    final double[] input = new double[] { 0.0, 0.25, -0.5, 10000.125, -99999.075 };
    ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
    JsonFactory f = JSON_F;
    JsonGenerator g = f.createGenerator(ObjectWriteContext.empty(), bytes);
    g.writeStartArray();
    for (int i = 0; i < input.length; ++i) {
        g.writeNumber(input[i]);
    }
    g.writeEndArray();
    g.close();
    byte[] data = bytes.toByteArray();
    _testDoubles(f, input, data, 0, 99);
    _testDoubles(f, input, data, 0, 3);
    _testDoubles(f, input, data, 0, 1);
    _testDoubles(f, input, data, 1, 99);
    _testDoubles(f, input, data, 1, 3);
    _testDoubles(f, input, data, 1, 1);
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 39 with JsonFactory

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

the class AsyncScalarArrayTest method testFloats.

/*
    /**********************************************************************
    /* Floating point
    /**********************************************************************
     */
public void testFloats() throws IOException {
    final float[] input = new float[] { 0.0f, 0.25f, -0.5f, 10000.125f, -99999.075f };
    ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
    JsonFactory f = JSON_F;
    JsonGenerator g = f.createGenerator(ObjectWriteContext.empty(), bytes);
    g.writeStartArray();
    for (int i = 0; i < input.length; ++i) {
        g.writeNumber(input[i]);
    }
    g.writeEndArray();
    g.close();
    byte[] data = bytes.toByteArray();
    _testFloats(f, input, data, 0, 100);
    _testFloats(f, input, data, 0, 3);
    _testFloats(f, input, data, 0, 1);
    _testFloats(f, input, data, 1, 100);
    _testFloats(f, input, data, 1, 3);
    _testFloats(f, input, data, 1, 1);
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 40 with JsonFactory

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

the class AsyncScalarArrayTest method testInts.

/*
    /**********************************************************************
    /* Int / long tests
    /**********************************************************************
     */
public void testInts() throws IOException {
    final int[] input = new int[] { 1, -1, 16, -17, 0, 131, -0, -155, 1000, -3000, 0xFFFF, -99999, Integer.MAX_VALUE, 0, Integer.MIN_VALUE };
    StringBuilder sb = new StringBuilder().append("[");
    for (int i = 0; i < input.length; ++i) {
        if (i > 0)
            sb.append(',');
        sb.append(input[i]);
    }
    byte[] data = _jsonDoc(sb.append(']').toString());
    JsonFactory f = JSON_F;
    _testInts(f, input, data, 0, 100);
    _testInts(f, input, data, 0, 3);
    _testInts(f, input, data, 0, 1);
    _testInts(f, input, data, 1, 100);
    _testInts(f, input, data, 1, 3);
    _testInts(f, input, data, 1, 1);
}
Also used : 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