本文整理汇总了Java中com.fasterxml.jackson.core.util.MinimalPrettyPrinter类的典型用法代码示例。如果您正苦于以下问题:Java MinimalPrettyPrinter类的具体用法?Java MinimalPrettyPrinter怎么用?Java MinimalPrettyPrinter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MinimalPrettyPrinter类属于com.fasterxml.jackson.core.util包,在下文中一共展示了MinimalPrettyPrinter类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSimpleDocWithMinimal
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
@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
// use TAB between array values
public 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();
}
示例2: testCustomSeparatorsWithMinimal
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
public void testCustomSeparatorsWithMinimal() throws Exception
{
StringWriter sw = new StringWriter();
JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
gen.setPrettyPrinter(new MinimalPrettyPrinter().setSeparators(Separators.createDefaultInstance()
.withObjectFieldValueSeparator('=')
.withObjectEntrySeparator(';')
.withArrayValueSeparator('|')));
_writeTestDocument(gen);
gen.close();
assertEquals("[3|\"abc\"|[true]|{\"f\"=null;\"f2\"=null}]", sw.toString());
}
示例3: to
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
@Override
public void to(final Writer out, final T object) {
try (StringWriter writer = new StringWriter()) {
this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object);
if (isJsonFormat()) {
final Stringify opt = this.prettyPrinter instanceof MinimalPrettyPrinter ? Stringify.FORMATTED : Stringify.FORMATTED;
JsonValue.readHjson(writer.toString()).writeTo(out, opt);
} else {
IOUtils.write(writer.toString(), out);
}
} catch (final Exception e) {
throw new IllegalArgumentException(e);
}
}
示例4: startPartition
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
@Override
public void startPartition(WritePartition partition) throws Exception {
// close previous partition if open.
if(this.partition != null){
close();
}
this.partition = partition;
try {
this.fileName = fs.canonicalizePath(partition.qualified(location, prefix + "_0." + extension));
stream = fs.create(fileName);
JsonGenerator generator = factory.createGenerator(stream).useDefaultPrettyPrinter();
if (uglify) {
generator = generator.setPrettyPrinter(new MinimalPrettyPrinter(LINE_FEED));
}
if(useExtendedOutput){
gen = new ExtendedJsonOutput(generator);
}else{
gen = new BasicJsonOutput(generator);
}
logger.debug("Created file: {}", fileName);
} catch (IOException ex) {
throw UserException.dataWriteError(ex)
.message("Failure writing JSON file %s.", fileName)
.build(logger);
}
}
示例5: BeanObjectJsonSerializer
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
/**
* Instantiates a new Bean object json serializer.
*/
public BeanObjectJsonSerializer() {
super(new MinimalPrettyPrinter());
}
示例6: initStructure
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
@Nullable
private String initStructure(CanvasSessionData data, SelectionSession session, SingleSignonForm form)
{
final String courseId = data.getCourseId();
String structure = form.getStructure();
if( structure == null )
{
// if course ID is empty then there is nothing we can do...
if( Strings.isNullOrEmpty(courseId) )
{
throw new RuntimeException(LABEL_ERROR_NO_COURSE.getText());
}
structure = courseStructureCache.get(courseId).orNull();
}
// if no structure, get from Canvas
if( structure == null )
{
final ObjectNode root = objectMapper.createObjectNode();
root.put("id", courseId);
root.put("name", data.getContextTitle());
root.put("targetable", false);
final ArrayNode foldersNode = objectMapper.createArrayNode();
root.put("folders", foldersNode);
final Connector connector = findConnector(data);
final List<ConnectorFolder> folders = connectorRepoService.getFoldersForCourse(connector,
CurrentUser.getUsername(), courseId, false);
boolean first = true;
for( ConnectorFolder folder : folders )
{
final ObjectNode folderNode = objectMapper.createObjectNode();
folderNode.put("id", folder.getId());
folderNode.put("name", folder.getName());
folderNode.put("targetable", true);
folderNode.put("defaultFolder", first);
foldersNode.add(folderNode);
first = false;
}
final PrettyPrinter pp = new MinimalPrettyPrinter();
try
{
structure = objectMapper.writer().with(pp).writeValueAsString(root);
}
catch( JsonProcessingException e )
{
throw Throwables.propagate(e);
}
}
if( structure != null )
{
courseStructureCache.put(courseId, structure);
}
return structure;
}
示例7: getStructure
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
private String getStructure(String courseId, String connectorUuid, String selected)
{
try
{
final boolean isDefaultApplicable = !Strings.isNullOrEmpty(selected);
final String cacheKey = connectorUuid + ":" + courseId + (!isDefaultApplicable ? "" : ":" + selected);
String structure = courseStructureCache.get(cacheKey).orNull();
// if no structure, get from Brightspace
if( structure == null )
{
final Connector connector = connectorService.getByUuid(connectorUuid);
if( connector == null )
{
throw new RuntimeException("No connector with UUID = " + connectorUuid);
}
final ConnectorCourse course = brightspaceService.getCourse(connector, courseId);
final ObjectNode root = objectMapper.createObjectNode();
root.put("id", courseId);
root.put("name", course.getName());
root.put("targetable", false);
final ArrayNode foldersNode = objectMapper.createArrayNode();
root.put("folders", foldersNode);
final List<ConnectorFolder> folders = brightspaceService.getFoldersForCourse(connector, null, courseId,
false);
boolean first = true;
for( ConnectorFolder folder : folders )
{
final ObjectNode folderNode = objectMapper.createObjectNode();
folderNode.put("id", folder.getId());
folderNode.put("name", folder.getName());
folderNode.put("targetable", true);
folderNode.put("selected",
(!isDefaultApplicable && first) || (isDefaultApplicable && selected.equals(folder.getId())));
foldersNode.add(folderNode);
first = false;
recurseFolder(connector, courseId, folder, folderNode, selected);
}
final PrettyPrinter pp = new MinimalPrettyPrinter();
try
{
structure = objectMapper.writer().with(pp).writeValueAsString(root);
}
catch( JsonProcessingException e )
{
throw Throwables.propagate(e);
}
if( structure == null )
{
// Can't happen
throw new RuntimeException("Could not create structure");
}
courseStructureCache.put(cacheKey, structure);
}
return structure;
}
catch( LmsUserNotFoundException lms )
{
throw Throwables.propagate(lms);
}
}
示例8: BeanObjectJsonSerializer
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
/**
* Instantiates a new Bean object json serializer.
*/
BeanObjectJsonSerializer() {
super(new MinimalPrettyPrinter());
}
示例9: init
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
@Override
public void init(Map<String, String> writerOptions) throws IOException {
this.location = writerOptions.get("location");
this.prefix = writerOptions.get("prefix");
this.fieldDelimiter = writerOptions.get("separator");
this.extension = writerOptions.get("extension");
this.useExtendedOutput = Boolean.parseBoolean(writerOptions.get("extended"));
this.skipNullFields = Boolean.parseBoolean(writerOptions.get("skipnulls"));
final boolean uglify = Boolean.parseBoolean(writerOptions.get("uglify"));
Configuration conf = new Configuration();
conf.set(FileSystem.FS_DEFAULT_NAME_KEY, writerOptions.get(FileSystem.FS_DEFAULT_NAME_KEY));
this.fs = FileSystem.get(conf);
Path fileName = new Path(location, prefix + "_" + index + "." + extension);
try {
// json writer does not support partitions, so only one file can be created
// and thus only one location should be deleted in case of abort
// to ensure that our writer was the first to create output file,
// we create empty output file first and fail if file exists
cleanUpLocation = storageStrategy.createFileAndApply(fs, fileName);
// since empty output file will be overwritten (some file systems may restrict append option)
// we need to re-apply file permission
stream = fs.create(fileName);
storageStrategy.applyToFile(fs, fileName);
JsonGenerator generator = factory.createGenerator(stream).useDefaultPrettyPrinter()
.configure(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS,
!Boolean.parseBoolean(writerOptions.get("enableNanInf")));
if (uglify) {
generator = generator.setPrettyPrinter(new MinimalPrettyPrinter(LINE_FEED));
}
if(useExtendedOutput){
gen = new ExtendedJsonOutput(generator);
}else{
gen = new BasicJsonOutput(generator);
}
logger.debug("Created file: {}", fileName);
} catch (IOException ex) {
logger.error("Unable to create file: " + fileName, ex);
throw ex;
}
}
示例10: JsonWriter
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
public JsonWriter(OutputStream os, Charset charset, ObjectMapper mapper) throws IOException {
generator = mapper.getFactory()
.createGenerator(new OutputStreamWriter(os, charset))
.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false)
.setPrettyPrinter(new MinimalPrettyPrinter(""));
}
示例11: newCompactPrinter
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; //导入依赖的package包/类
@Override
protected PrettyPrinter newCompactPrinter() {
return new MinimalPrettyPrinter();
}