本文整理汇总了Java中com.fasterxml.jackson.core.util.DefaultIndenter类的典型用法代码示例。如果您正苦于以下问题:Java DefaultIndenter类的具体用法?Java DefaultIndenter怎么用?Java DefaultIndenter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultIndenter类属于com.fasterxml.jackson.core.util包,在下文中一共展示了DefaultIndenter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: marshalJson
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
public static String marshalJson(CASServiceResponse serviceResponse) {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//Force newlines to be LF (default is system dependent)
DefaultPrettyPrinter printer = new DefaultPrettyPrinter()
.withObjectIndenter(new DefaultIndenter(" ", "\n"));
//create wrapper node
Map<String, Object> casModel = new HashMap<>();
casModel.put("serviceResponse", serviceResponse);
try {
return mapper.writer(printer).writeValueAsString(casModel);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
示例2: testCustomSeparatorsWithPP
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
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());
}
示例3: testCustomSeparatorsWithPPWithoutSpaces
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
public void testCustomSeparatorsWithPPWithoutSpaces() throws Exception
{
StringWriter sw = new StringWriter();
JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
gen.setPrettyPrinter(new DefaultPrettyPrinter().withSeparators(Separators.createDefaultInstance()
.withObjectFieldValueSeparator('=')
.withObjectEntrySeparator(';')
.withArrayValueSeparator('|'))
.withoutSpacesInObjectEntries());
_writeTestDocument(gen);
gen.close();
assertEquals("[ 3| \"abc\"| [ true ]| {" + DefaultIndenter.SYS_LF +
" \"f\"=null;" + DefaultIndenter.SYS_LF +
" \"f2\"=null" + DefaultIndenter.SYS_LF +
"} ]", sw.toString());
}
示例4: createJsonWriter
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
@Nonnull
private static ObjectWriter createJsonWriter(final boolean prettyPrint) {
final ObjectMapper mapper = new ObjectMapper();
if (!prettyPrint) {
return mapper.writer();
}
final DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(" ", DefaultIndenter.SYS_LF);
final DefaultPrettyPrinter printer = new DefaultPrettyPrinter("");
printer.withoutSpacesInObjectEntries();
printer.indentObjectsWith(indenter);
printer.indentArraysWith(indenter);
return mapper.writer(printer);
}
示例5: toString
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
/**
@return The JSON pretty-printed representation of this configuration.
*/
@Override
public final String toString() {
final ObjectMapper mapper = new ObjectMapper()
.configure(SerializationFeature.INDENT_OUTPUT, true);
final DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(
"\t", DefaultIndenter.SYS_LF
);
final DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
printer.withObjectIndenter(indenter);
printer.withArrayIndenter(indenter);
try {
return mapper.writer(printer).writeValueAsString(this);
} catch(final JsonProcessingException e) {
throw new AssertionError(e);
}
}
示例6: afterPropertiesSet
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
super.setModules(this.modules);
super.afterPropertiesSet();
ObjectMapper objMapper = this.getObject();
DefaultIndenter indenter = new DefaultIndenter(StringUtils.repeat(StringUtils.SPACE, this.indentSize), StringUtils.LF);
SdcctPrettyPrinter prettyPrinter = new SdcctPrettyPrinter(indenter.getIndent());
prettyPrinter.indentArraysWith(indenter);
prettyPrinter.indentObjectsWith(indenter);
objMapper.setDefaultPrettyPrinter(prettyPrinter);
objMapper.setPropertyInclusion(this.propInclusion);
}
示例7: prettyPrint
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
@SuppressWarnings("unused")
private static void prettyPrint(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(json);
CustomPrettyPrinter prettyPrinter = new CustomPrettyPrinter();
prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);
StringBuilder sb = new StringBuilder();
JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb))
.setPrettyPrinter(prettyPrinter);
jg.writeTree(node);
jg.close();
System.out.println(sb.toString().replace("\"", "\\\"").replace(DefaultIndenter.SYS_LF,
"\"" + DefaultIndenter.SYS_LF + " + \""));
}
示例8: prettyMapper
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
private static ObjectMapper prettyMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setBase64Variant(Base64Variants.MODIFIED_FOR_URL);
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.registerModule(tuuidModule());
if (!Env.dev()) {
mapper.registerModule(new AfterburnerModule());
}
DefaultPrettyPrinter pp = new DefaultPrettyPrinter();
pp = pp.withObjectIndenter(new DefaultIndenter(" ", "\n"));
mapper.setDefaultPrettyPrinter(pp);
return mapper;
}
示例9: getObjectWriter
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
/**
* Static factory that creates {@link com.fasterxml.jackson.databind.ObjectWriter}s.
*
* @return utility that will allow client to serialize wrapper contents as json
*/
public static ObjectWriter getObjectWriter(boolean filterMeta) {
DefaultIndenter withLinefeed = new DefaultIndenter(" ", "\n");
DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
printer.indentObjectsWith(withLinefeed);
ObjectMapper om = new ObjectMapper();
if (filterMeta) {
outfitMetadataFilter(om);
}
return om.writer().with(printer);
}
示例10: JacksonPrettyPrinter
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
public JacksonPrettyPrinter(int indent) {
super();
StringBuilder indentSpaces = new StringBuilder();
while (indentSpaces.length() < indent)
indentSpaces.append(" ");
super._objectIndenter = new DefaultIndenter(indentSpaces.toString(), DefaultIndenter.SYS_LF);
super._arrayIndenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
}
示例11: NpmJsonPrettyPrinter
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
public NpmJsonPrettyPrinter() {
this._objectFieldValueSeparatorWithSpaces = ": ";
Indenter indenter = new DefaultIndenter(" ", System.lineSeparator());
this.indentObjectsWith(indenter);
this.indentArraysWith(indenter);
}
示例12: afterPropertiesSet
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
super.afterPropertiesSet();
DefaultIndenter indenter = new DefaultIndenter(StringUtils.repeat(StringUtils.SPACE, this.indentSpaces), StringUtils.LF);
CrigttPrettyPrinter prettyPrinter = new CrigttPrettyPrinter(indenter.getIndent());
prettyPrinter.indentArraysWith(indenter);
prettyPrinter.indentObjectsWith(indenter);
this.getObject().setDefaultPrettyPrinter(prettyPrinter);
}
示例13: serialize
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
private String serialize(JsonGraph jsonGraph) {
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter()
.withObjectIndenter(new DefaultIndenter(" ", "\n"));
ObjectWriter writer = this.objectMapper.writer(prettyPrinter);
StringWriter jsonWriter = new StringWriter();
try {
writer.writeValue(jsonWriter, jsonGraph);
} catch (IOException e) {
// should never happen with StringWriter
throw new IllegalStateException(e);
}
return jsonWriter.toString();
}
示例14: StandardJsonPrettyPrinter
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
public StandardJsonPrettyPrinter(String indent, String eol) {
this.indent = indent;
this.eol = eol;
final DefaultIndenter indenter = new DefaultIndenter(indent, eol);
this._arrayIndenter = indenter;
this._objectIndenter = indenter;
}
示例15: SmartObjectMapper
import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
/**
* This constructor creates a new smart object mapper for the specified modules.
*
* @param modules The modules to be registered.
*/
SmartObjectMapper(Module... modules) {
super();
// indent the output
enable(SerializationFeature.INDENT_OUTPUT);
// allow empty beans
disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
// don't serialize nulls
disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
setSerializationInclusion(Include.NON_NULL);
// don't fail on unknown properties
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// write dates out as string (not milliseconds since epoch <- timestamp)
disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
// handle joda types
registerModule(new JodaModule());
// handle primitive types that can generate strings
addMixIn(craterdog.primitives.BinaryString.class, UseToStringAsValueMixIn.class);
addMixIn(craterdog.primitives.Tag.class, UseToStringAsValueMixIn.class);
addMixIn(craterdog.primitives.TextString.class, UseToStringAsValueMixIn.class);
addMixIn(java.net.URI.class, UseToStringAsValueMixIn.class);
// handle primitive types that can generate doubles
addMixIn(craterdog.primitives.Angle.class, UseToDoubleAsValueMixIn.class);
addMixIn(craterdog.primitives.Probability.class, UseToDoubleAsValueMixIn.class);
// add any additional modules passed in
for (Module module : modules) {
registerModule(module);
}
setDefaultPrettyPrinter(new BetterPrettyPrinter().withArrayIndenter(new DefaultIndenter()));
}