use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project jackson-core by FasterXML.
the class ParserErrorHandlingTest method _testMangledNumbersFloat.
private void _testMangledNumbersFloat(int mode) throws Exception {
// Also test with floats
JsonParser p = createParser(mode, "1.5false");
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: " + t);
} catch (JsonParseException e) {
verifyException(e, "expected space");
}
p.close();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project jackson-core by FasterXML.
the class ParserErrorHandlingTest method _testMangledNumbersInt.
private void _testMangledNumbersInt(int mode) throws Exception {
JsonParser p = createParser(mode, "123true");
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: " + t);
} catch (JsonParseException e) {
verifyException(e, "expected space");
}
p.close();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project jackson-core by FasterXML.
the class Surrogate223Test method testSurrogatesByteBacked.
// for [core#223]
public void testSurrogatesByteBacked() throws Exception {
ByteArrayOutputStream out;
JsonGenerator g;
final String toQuote = new String(Character.toChars(0x1F602));
// just sanity check
assertEquals(2, toQuote.length());
// default should be disabled:
// assertFalse(JSON_F.isEnabled(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES));
out = new ByteArrayOutputStream();
g = JSON_F.createGenerator(ObjectWriteContext.empty(), out);
g.writeStartArray();
g.writeString(toQuote);
g.writeEndArray();
g.close();
// brackets, quotes, 4-byte encoding
assertEquals(2 + 2 + 4, out.size());
// Also parse back to ensure correctness
JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), out.toByteArray());
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertToken(JsonToken.END_ARRAY, p.nextToken());
p.close();
// but may revert back to original behavior
out = new ByteArrayOutputStream();
g = JSON_F.createGenerator(ObjectWriteContext.empty(), out);
// g.enable(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES);
g.writeStartArray();
g.writeString(toQuote);
g.writeEndArray();
g.close();
// brackets, quotes, 2 x 6 byte JSON escape
assertEquals(2 + 2 + 12, out.size());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project jackson-core by FasterXML.
the class Surrogate223Test method testSurrogatesCharBacked.
// for [core#223]
public void testSurrogatesCharBacked() throws Exception {
Writer out;
JsonGenerator g;
final String toQuote = new String(Character.toChars(0x1F602));
// just sanity check
assertEquals(2, toQuote.length());
// default should be disabled:
// assertFalse(JSON_F.isEnabled(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES));
out = new StringWriter();
g = JSON_F.createGenerator(ObjectWriteContext.empty(), out);
g.writeStartArray();
g.writeString(toQuote);
g.writeEndArray();
g.close();
// brackets, quotes, 2 chars as is
assertEquals(2 + 2 + 2, out.toString().length());
// Also parse back to ensure correctness
JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), out.toString());
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertToken(JsonToken.END_ARRAY, p.nextToken());
p.close();
// but may revert back to original behavior
out = new StringWriter();
g = JSON_F.createGenerator(ObjectWriteContext.empty(), out);
// g.enable(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES);
g.writeStartArray();
g.writeString(toQuote);
g.writeEndArray();
g.close();
// brackets, quotes, 2 x 6 byte JSON escape
assertEquals(2 + 2 + 12, out.toString().length());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project jackson-core by FasterXML.
the class TestParserOverrides method _testTokenAccess.
/*
/**********************************************************
/* Actual test methods
/**********************************************************
*/
public void _testTokenAccess(JsonFactory jf, boolean useStream) throws Exception {
final String DOC = "[ ]";
JsonParser jp = useStream ? jf.createParser(ObjectReadContext.empty(), new ByteArrayInputStream(DOC.getBytes("UTF-8"))) : jf.createParser(ObjectReadContext.empty(), DOC);
assertNull(jp.currentToken());
jp.clearCurrentToken();
assertNull(jp.currentToken());
assertNull(jp.getEmbeddedObject());
assertToken(JsonToken.START_ARRAY, jp.nextToken());
assertToken(JsonToken.START_ARRAY, jp.currentToken());
jp.clearCurrentToken();
assertNull(jp.currentToken());
// Also: no codec defined by default
try {
jp.readValueAsTree();
fail("Should get exception without codec");
} catch (UnsupportedOperationException e) {
verifyException(e, "Operation not supported");
}
jp.close();
}
Aggregations