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