use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project topcom-cloud by 545314690.
the class MyWebAppConfigurer method extendMessageConverters.
/**
* 添加返回结果缩进支持,如果存在pretty参数,则返回结果添加缩进
* @param converters
*/
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.replaceAll(c -> {
if (c instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(mapper) {
@Override
protected void writePrefix(JsonGenerator generator, Object object) throws IOException {
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
if (attributes != null && attributes instanceof ServletRequestAttributes) {
String attribute = ((ServletRequestAttributes) attributes).getRequest().getParameter("pretty");
if (attribute != null) {
generator.setPrettyPrinter(new DefaultPrettyPrinter());
}
}
super.writePrefix(generator, object);
}
};
return converter;
} else {
return c;
}
});
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project kylo by Teradata.
the class FilesystemRepositoryService method importTemplate.
@Override
public ImportTemplate importTemplate(String repositoryName, String repositoryType, String fileName, String uploadKey, String importComponents) throws Exception {
Optional<TemplateRepository> repository = listRepositories().stream().filter(r -> StringUtils.equals(r.getName(), repositoryName) && StringUtils.equals(r.getType().getKey(), repositoryType)).findFirst();
Path filePath = Paths.get(repository.get().getLocation() + "/" + fileName);
if (!filePath.toFile().exists()) {
throw new RuntimeException("Unable to find template file to import: " + fileName);
}
log.info("Begin template import {}", fileName);
ImportTemplateOptions options = new ImportTemplateOptions();
options.setUploadKey(uploadKey);
byte[] content = ImportUtil.streamToByteArray(new FileInputStream(filePath.toFile()));
String checksum = DigestUtils.md5DigestAsHex(content);
uploadProgressService.newUpload(uploadKey);
ImportTemplate importTemplate = null;
TemplateImporter templateImporter = null;
if (importComponents == null) {
templateImporter = templateImporterFactory.apply(fileName, content, options);
importTemplate = templateImporter.validate();
importTemplate.setSuccess(false);
} else {
options.setImportComponentOptions(ObjectMapperSerializer.deserialize(importComponents, new TypeReference<Set<ImportComponentOption>>() {
}));
templateImporter = templateImporterFactory.apply(fileName, content, options);
importTemplate = templateImporter.validateAndImport();
}
log.info("End template import {} - {}", fileName, importTemplate.isSuccess());
// update template metadata
String baseName = FilenameUtils.getBaseName(fileName);
Path metadataPath = Paths.get(repository.get().getLocation() + "/" + baseName + ".json");
TemplateMetadata templateMetadata = mapper.readValue(metadataPath.toFile(), TemplateMetadata.class);
templateMetadata.setChecksum(checksum);
long updateTime = importTemplate.getTemplateToImport().getUpdateDate().getTime();
templateMetadata.setLastModified(updateTime);
templateMetadata.setUpdateAvailable(false);
mapper.writer(new DefaultPrettyPrinter()).writeValue(metadataPath.toFile(), templateMetadata);
log.info("Generated checksum for {} - {}", templateMetadata.getTemplateName(), checksum);
templateUpdateInfoCache.put(templateMetadata.getTemplateName(), false);
return importTemplate;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method startDocument.
@Override
public void startDocument() throws QueryResultHandlerException {
if (!documentOpen) {
documentOpen = true;
headerOpen = false;
headerComplete = false;
tupleVariablesFound = false;
firstTupleWritten = false;
linksFound = false;
if (getWriterConfig().get(BasicWriterSettings.PRETTY_PRINT)) {
// SES-2011: Always use \n for consistency
Indenter indenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
// By default Jackson does not pretty print, so enable this unless
// PRETTY_PRINT setting is disabled
DefaultPrettyPrinter pp = new DefaultPrettyPrinter().withArrayIndenter(indenter).withObjectIndenter(indenter);
jg.setPrettyPrinter(pp);
}
try {
if (getWriterConfig().isSet(BasicQueryWriterSettings.JSONP_CALLBACK)) {
// SES-1019 : Write the callbackfunction name as a wrapper for
// the results here
String callbackName = getWriterConfig().get(BasicQueryWriterSettings.JSONP_CALLBACK);
jg.writeRaw(callbackName);
jg.writeRaw("(");
}
jg.writeStartObject();
} catch (IOException e) {
throw new QueryResultHandlerException(e);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project jackson-core by FasterXML.
the class CoreJDKSerializabilityTest method testPrettyPrinter.
public void testPrettyPrinter() throws Exception {
PrettyPrinter p = new DefaultPrettyPrinter();
byte[] stuff = jdkSerialize(p);
PrettyPrinter back = jdkDeserialize(stuff);
// what should we test?
assertNotNull(back);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project jackson-core by FasterXML.
the class TestPrettyPrinter method testCustomRootSeparatorWithPP.
// [Issue#26]
public void testCustomRootSeparatorWithPP() throws Exception {
JsonFactory f = new JsonFactory();
// first, no pretty-printing (will still separate root values with a space!)
assertEquals("{} {} []", _generateRoot(f, null));
// First with default pretty printer, default configs:
assertEquals("{ } { } [ ]", _generateRoot(f, new DefaultPrettyPrinter()));
// then custom:
assertEquals("{ }|{ }|[ ]", _generateRoot(f, new DefaultPrettyPrinter("|")));
}
Aggregations