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