use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class AsyncStringObjectTest method testBasicFieldsNames.
public void testBasicFieldsNames() throws IOException {
final String json = aposToQuotes(String.format("{'%s':'%s','%s':'%s','%s':'%s'}", UNICODE_SHORT_NAME, UNICODE_LONG_NAME, UNICODE_LONG_NAME, UNICODE_SHORT_NAME, ASCII_SHORT_NAME, ASCII_SHORT_NAME));
final JsonFactory f = JSON_F;
byte[] data = _jsonDoc(json);
_testBasicFieldsNames(f, data, 0, 100);
_testBasicFieldsNames(f, data, 0, 3);
_testBasicFieldsNames(f, data, 0, 1);
_testBasicFieldsNames(f, data, 1, 100);
_testBasicFieldsNames(f, data, 1, 3);
_testBasicFieldsNames(f, data, 1, 1);
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestGeneratorArray method testSimpleArrayWrite.
public void testSimpleArrayWrite() throws Exception {
StringWriter sw = new StringWriter();
JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
gen.writeStartArray();
gen.writeNumber(13);
gen.writeBoolean(true);
gen.writeString("foobar");
gen.writeEndArray();
gen.close();
String docStr = sw.toString();
JsonParser jp = createParserUsingReader(docStr);
assertEquals(JsonToken.START_ARRAY, jp.nextToken());
assertEquals(JsonToken.VALUE_NUMBER_INT, jp.nextToken());
assertEquals(13, jp.getIntValue());
assertEquals(JsonToken.VALUE_TRUE, jp.nextToken());
assertEquals(JsonToken.VALUE_STRING, jp.nextToken());
assertEquals("foobar", jp.getText());
assertEquals(JsonToken.END_ARRAY, jp.nextToken());
assertEquals(null, jp.nextToken());
jp.close();
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestGeneratorCopy method testCopyObjectTokens.
public void testCopyObjectTokens() throws IOException {
JsonFactory jf = new JsonFactory();
final String DOC = "{ \"a\":1, \"b\":[{ \"c\" : null }] }";
JsonParser jp = jf.createParser(ObjectReadContext.empty(), new StringReader(DOC));
StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(ObjectWriteContext.empty(), sw);
assertToken(JsonToken.START_OBJECT, jp.nextToken());
gen.copyCurrentStructure(jp);
// which will advance parser to matching end Object
assertToken(JsonToken.END_OBJECT, jp.currentToken());
jp.close();
gen.close();
assertEquals("{\"a\":1,\"b\":[{\"c\":null}]}", sw.toString());
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestGeneratorCopy method testCopyArrayTokens.
public void testCopyArrayTokens() throws IOException {
JsonFactory jf = new JsonFactory();
final String DOC = "123 [ 1, null, [ false ] ]";
JsonParser jp = jf.createParser(ObjectReadContext.empty(), new StringReader(DOC));
StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(ObjectWriteContext.empty(), sw);
assertToken(JsonToken.VALUE_NUMBER_INT, jp.nextToken());
gen.copyCurrentEvent(jp);
// should not change parser state:
assertToken(JsonToken.VALUE_NUMBER_INT, jp.currentToken());
assertEquals(123, jp.getIntValue());
// And then let's copy the array
assertToken(JsonToken.START_ARRAY, jp.nextToken());
gen.copyCurrentStructure(jp);
// which will advance parser to matching close Array
assertToken(JsonToken.END_ARRAY, jp.currentToken());
jp.close();
gen.close();
assertEquals("123 [1,null,[false]]", sw.toString());
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestGeneratorCopy method testCopyRootTokens.
public void testCopyRootTokens() throws IOException {
JsonFactory jf = new JsonFactory();
final String DOC = "\"text\\non two lines\" true false 2.0";
JsonParser jp = jf.createParser(ObjectReadContext.empty(), new StringReader(DOC));
StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(ObjectWriteContext.empty(), sw);
JsonToken t;
while ((t = jp.nextToken()) != null) {
gen.copyCurrentEvent(jp);
// should not change parser state:
assertToken(t, jp.currentToken());
}
jp.close();
gen.close();
assertEquals("\"text\\non two lines\" true false 2.0", sw.toString());
}
Aggregations