use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestPrettyPrinter method testSimpleDocWithMinimal.
@SuppressWarnings("resource")
public void testSimpleDocWithMinimal() throws Exception {
StringWriter sw = new StringWriter();
JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
// first with standard minimal
gen.setPrettyPrinter(new MinimalPrettyPrinter());
String docStr = _verifyPrettyPrinter(gen, sw);
// which should have no linefeeds, tabs
assertEquals(-1, docStr.indexOf('\n'));
assertEquals(-1, docStr.indexOf('\t'));
// And then with slightly customized variant
gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
gen.setPrettyPrinter(new MinimalPrettyPrinter() {
@Override
public // use TAB between array values
void beforeArrayValues(JsonGenerator jg) throws IOException, JsonGenerationException {
jg.writeRaw("\t");
}
});
docStr = _verifyPrettyPrinter(gen, sw);
assertEquals(-1, docStr.indexOf('\n'));
assertTrue(docStr.indexOf('\t') >= 0);
gen.close();
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestPrettyPrinter method testCustomSeparatorsWithPP.
public void testCustomSeparatorsWithPP() throws Exception {
StringWriter sw = new StringWriter();
JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
gen.setPrettyPrinter(new DefaultPrettyPrinter().withSeparators(Separators.createDefaultInstance().withObjectFieldValueSeparator('=').withObjectEntrySeparator(';').withArrayValueSeparator('|')));
_writeTestDocument(gen);
gen.close();
assertEquals("[ 3| \"abc\"| [ true ]| {" + DefaultIndenter.SYS_LF + " \"f\" = null;" + DefaultIndenter.SYS_LF + " \"f2\" = null" + DefaultIndenter.SYS_LF + "} ]", sw.toString());
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class CommentParsingTest method testDefaultSettings.
/*
/**********************************************************
/* Test method wrappers
/**********************************************************
*/
/**
* Unit test for verifying that by default comments are not
* recognized.
*/
public void testDefaultSettings() throws Exception {
JsonFactory f = new JsonFactory();
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
JsonParser p = f.createParser(ObjectReadContext.empty(), new StringReader("[ 1 ]"));
assertFalse(p.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
p.close();
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class CommentParsingTest method testYAMLCommentsBytes.
public void testYAMLCommentsBytes() throws Exception {
JsonFactory f = JsonFactory.builder().enable(JsonParser.Feature.ALLOW_YAML_COMMENTS).build();
_testYAMLComments(f, MODE_INPUT_STREAM);
_testCommentsBeforePropValue(f, MODE_INPUT_STREAM, "# foo\n");
_testYAMLComments(f, MODE_INPUT_STREAM_THROTTLED);
_testCommentsBeforePropValue(f, MODE_INPUT_STREAM_THROTTLED, "# foo\n");
_testYAMLComments(f, MODE_DATA_INPUT);
_testCommentsBeforePropValue(f, MODE_DATA_INPUT, "# foo\n");
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class CommentParsingTest method testYAMLCommentsChars.
public void testYAMLCommentsChars() throws Exception {
JsonFactory f = JsonFactory.builder().enable(JsonParser.Feature.ALLOW_YAML_COMMENTS).build();
_testYAMLComments(f, MODE_READER);
final String COMMENT = "# foo\n";
_testCommentsBeforePropValue(f, MODE_READER, COMMENT);
_testCommentsBetweenArrayValues(f, MODE_READER, COMMENT);
}
Aggregations